BookNotes I - Refactoring Workbook (Willian C. Wake)

For future reference, here are few things to look for during refactoring the source.

Comments
-          Lots of comment explaining a piece of code -> Extract the code in a separate method
-          When comment explains preconditions -> Use Assertions

Long Method
-          Look for comments to extract methods
-          Extract methods semantically

Long Class
-          Extract class if there are too many responsibilities
-          Extract interface if you can identify subset of features that clients can use

Long Parameter List
-          See if the method is being used to do more than 1 action and the logic is controlled by the parameters ( eg. Add/Update in a single method )
-          If the parameters come from a single object, pass the object or extract an object out of parameters

Names
-          Avoid Hungarian notations
-          Name the method so that it communicates to other people ( Avoid One or Two Character names, Numbered variables, Odd abbreviations, Misleading names )

Unnecessary Complexity
-          Dead code
-          YAGNI principle ( avoid unnecessary generalization )

Duplication
-          Magic Number -> Replace numbers inside code body into symbolic constants
-          Extract Methods to pull duplication code and put it inside the most appropriate class. Otherwise, extract a class and use it.
-          Combine classes if two classes are doing mostly similar stuff.

No Comments