Friday, July 30, 2010

Clean Code


Nothing epic in this one - except the bit about commenting!



http://www.briankotek.com/blog/



Variables:

Intention

No Cryptic Names

No Internal Abbreviations

Be Serious



Question- does a word length affect processing time?




Don't use i

Don't use temp

Don't use Arr



For loops - use "thisSomething" - makes things clearer inside big loops


If/Else and Switch/Case


Minimize use

Simple conditions - try to avoid (if and ( OR) And NoT )

Break it up.

Avoid nesting

Don't assume something will run. Try to add a else catchall




Loops - avoid nesting.

Put nested loops in their own functions:




Naming.


Method/Function Names:

Use Verb orientated names

updateFeed()


Methods;

Smaller==better

More cohesive

Easier to test

Easier to override



Functions/Methods - return the result and act on it, don't do stuff inside and return a true/false



Error Codes (I do this badly)

Use Exceptions.



Classes/CFCs

Noun Oriented Names



DON'T COMMENT CODE!

A comment is a failure :-)

Make the code the comment.

If you absolutely have to, explain WHAT now HOW



DON'T COMMENT OUT CODE.

Comments are not version control!

All it offers is confusion.


Comments are obliged to be updated, so you'll always need to update them.














No comments:

Post a Comment

Note: Only a member of this blog may post a comment.