Code Smells – Code that stinks

Code Smell

Read the below line and if you get some feeling near your nose, that’s code smell.

Hello Everyones,

Todays is a great day. I is happy because we are learning new thing’s.

As per wiki – Smells are certain structures in the code that indicate a violation of fundamental design principles and negatively impact design quality. Bad code smells is usually an indicator of factors that affect the Technical Debt.

Code smell

  • Doesn’t tell what to do but tells us what to notice in our code. What patterns to look for.
  • Its closely associated with code reviews. While reviewing the code we don’t go thru each and every line of code for finding smells, instead, we look for patterns or in short, we look for code that smells.
  • Calling something a code smell is not an attack, it’s simply a sign that a closer look is required; Give closer look and then decide if any code change is required or not.
  • While working on an assignment, it may not be possible to refactor or fix the code smell, but when you observe the smell, it would be very wise for you to put a // @FIXME or // @TODO type of comments indicating the code smell and short about how it can be fixed. This goes a long way in keeping your technical debt low. Most IDEs have an option to list all such FIXME / TODO type of actionable comments.
  • In order to clean the code, its very important to understand what are the different code smells. It gives you an indication of what to look for.
  • It will help us to narrow down the techniques we might use for refactoring.
  • It’s an agile software development term and practice.
  • It will help us to narrow down the techniques we might use for refactoring.

Different Code Smells

Bloaters

Code accumulated over time as the program evolves and when nobody makes an effort to eradicate them. Code smells that are categorized as “Bloaters” are:

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

Object-Orientation Abusers

Incomplete or incorrect application of object-oriented programming principles. Code smells that are categorized as “Object-Orientation Abusers” are:

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

Change Preventers

To do a small change, you need to change many other places. Code smells that are categorized as “Change Preventers” are:

  • Divergent Change
  • Parallel Inheritance Hierarchies
  • Shotgun Surgery

Dispensables

The pointless and unneeded whose absence would make the code cleaner. Code smells that are categorized as “Dispensables” are:

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

Couplers

Excessive coupling between classes. Code smells that are categorized as “Couplers” are:

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