Tuesday, June 17, 2014

Less Comments, More Functions

Comments are vital to every software package.  I'm sure at some point we've all come across some code that we would have liked to know what the original (or perhaps it was our previous self) was intending...  At that point, we immediately look around for a comment or two.

However, what if the comment is out of date?  When this happens, I think the comment is quite destructive and should be deleted.  So why does this happen?  I think we've all been in a situation where we are changing code and while we're concerned about what the compiler thinks and the end results... we neglect the comments that were included with the code.  Perhaps we have every intention to go back and fix them... but never find the time...

I know I run into this more often than I would like...  To prevent this I have adopted a style that strives to self document.  I write several little functions that have a single intention and a descriptive name.  I believe and find that coders will change the name of methods and functions before they change a bunch of comments.  I've also found that coders prefer to look at code!  In fact, if you take the approach of writing code that is simple and concise, its likely that most coders will be able to read your intentions far easier that deciphering a grammatically challenged statement riddled with words that are misspelled.

This could quickly become a rant... So I'll stop here.  Feel free to post your favorite comments you've ever written/encountered... Or even just some pet peeves...