Saturday, July 27, 2013

About Green Code

Commenting code is one thing. Documenting it is a completely different thing. And both have two categories: useful and useless. Let me show you what I'm talking about.

1 – Commenting Code


Why on earth would you do something like this? If "x" and "y" are never used, cool: remove the line! Also, commenting with // and then /**/ is annoying! Do not mix the way you comment lines. Use a pattern! You can use both ways for commenting, but just follow some guidelines! At the limit, it "blows" the shortcuts in VisualStudio.


Ok, somewhere in time that HasProfile stuff was used. Or It probably will be. Or it makes sense. Or the client was not sure if that should be a rule or not and wanted to see how males interact with some feature but not sure if it will be a definite one or the limitation on female will be back. Cool, don't delete. Avoid rewriting everything again! At the limit, you could delete it (that's why we have Source Control Systems), but it's easier this way.

2 – Documenting Code


Cool! This is the worst! Code is self-explanatory and if you're not going to add any extra valuable information, then don't write anything. It only makes it less readable.


(click to enlarge)

Green code is not about having lots of green color on your screen. It's about having useful, meaningful and extra-valuable information placed in specific (strategic) spots that can make a difference and be helpful in the future.