12/11/2004

What is clean code?

Coding standards are language and project dependent. Some C/C++ teams strictly think all local variables in a method should be declared at the begining of the method, some think a method should have only one return statement, Some encourage anonymous inner classes and some out right hate them.
So What is clean code? Is it the code that follows coding, documenation and testing standards. Can we apply bookish knowledge--ofcode smells,best practices, and freak out on switch case statements, series of if-elses, instanceofs, lack of test cases etc. Or on the contrary, a nice looking (unsmelly)program that has javadocs, test cases and follows some bookish buzz words is always clean code?
We programmers (perhaps human tendancy) don't accept other's code as clean. More over in a large team with group politics, it is even worse, one group thinks rival group's code is crap, and vice versa. IMO 90% of the cases, calling code bad, horrible, crap is for personal or political reasons.