Saturday, May 26, 2012

Code Smells & Coding Standards

What is smell? Its a symptom of a possible deeper problem. Lets say you are cooking something and there is an unusual smell. You will immediately come to know there could be something wrong that went while cooking. You can't say the smell is indicating something bad when you are novice in cooking. Identifying smell requires little experience. The same applies for computer programming also.
Code Smells is a hint that something has gone wrong somewhere in the code. Code smells are possible bad practices used while coding. Following stuffs are all referred as code smells.

1. Large files
2. Large functions
3. Large function parameter list
4. Commented Code
5. Complex Conditional Logic
6. Switch case or if else on someone Else's data
7. Duplication of information
8. Multiple meanings to a variable - Same variable is used in different ways inside a single function or single class
9. Inconsistent parameter ordering across methods
10.Feature Envy - Method needing too much information from another object.
11. Data clumps - Data use always together.
12. Parallel inheritance hierarchies
13. Lazy class - class with no intent
14. Middle man - Too much delegating methods
15. Temp Field
16. Message Chains
17. Data classes - Class with only getter and setter methods.

Coding Standards

1. Avoid TODO's or FIX-ME's - These pass the test cases and hide the possible errors and the wrong impression at the test report that everything is implemented.
2.  Document the side effects - Document why than how and update them actively
3. Use tabs or spaces but not both
4. Put curly braces at the same level
5. Do not have long line lengths
6. Do not use type information in the variables
7. Avoid being abstract, do not use variables like 'it', 'everything', 'data','handle','stuff','perform' etc
8. Whenever copy paste occurs, refactor into a method
10. Do not have comment history in the file header if you are using version control
11. Do not mention bug ids in the source, instead mention that as code commit comment.

In other words do the negation of what is mentioned at http://thc.org/root/phun/unmaintain.html

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...