Code Smells

Code Smells

Quick intro

– What? How can code "smell"?? – Well it doesn't have a nose... but it definitely can stink!

You must train yourself to recognize when these smells require attention, what are those smells and how to remove them.

What is a code smell?

In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem. The determination of code smell is subjective and depends on the language, developer, and development technology.

Bloaters

Bloaters are code, methods, and classes that have increased to such proportions that they are hard to work with.

  • Long Method
  • Large Class
  • Primitive Obsession
  • Long Parameter List
  • Data Clumps

Object orientation abusers

All these smells are incomplete or incorrect applications of object-oriented programming principles.

  • Switch Statements
  • Temporary Field
  • Refused Bequest
  • Alternative Classes with Different Interfaces

Change preventers

These smells mean that if you need to change something in one place in your code, you have to make many changes in other places too.

  • Divergent Change
  • Shotgun Surgery
  • Parallel Inheritance Hierarchies

Dispensables

A dispensable is something pointless and unneeded whose absence would make the code cleaner, more efficient, and easier to understand.

  • Comments
  • Duplicate Code
  • Lazy class
  • Data Class
  • Dead Code
  • Speculative Generality

Couplers

All the smells in this group contribute to the excessive coupling between classes or show what happens if the coupling is replaced by excessive delegation.

  • Feature Envy
  • Inappropriate Intimacy
  • Message chains
  • Middle Man
  • Incomplete Library Class

If you would like to know more about code smells and how to fix them let me know. In the meantime, I strongly recommend Refactoring Improving the Design of Existing Code by Martin Fowler, with Kent Beck or Refactoring Guru.

Get in touch with me via LinkedIn in case you would like to talk more :)