Code Smells: how to refactor

In this post I am going to explain about code smells and how to remove to those code  smells from your code base

What is code smells: A code smell is a hint that something has gone wrong somewhere in your code

Kent back’s rule of simple design
design code should
1. run all the specs(successfully pass)
2. contains no duplicate code
3. express intent should be present
4. minimize class and methods size(SRP).
code smells:
  1. Long Method
refactor: break down onto short methods
why ?
easy to write test
more descriptive name
easy to understand whats going inside the method
one line method (holy grail)
2. large class: breaking the SRP

Problems:
large class have too many instance variable
too many method
refactor: Obey SRP

3. Primitive Obsession : using primitive data types to represent domain ideas
refactor: ValueObject in place of the primitive data
what is value Object: Examples of value objects are things like numbers, dates, monies and strings.

4. Data clump: set of data that always used together but are not organized together
refactor: Whenever two or three values are gathered together – turn them into a object.
5. Poor Name:
refactor: Name should be descriptive
use standard term
be unambiguous
describe side effect
be longer when scope is large

References: http://c2.com/