The Gift of GaB

My rants, writings, outpourings, musings and whatever else can be penned/typed down!

Wednesday, April 19, 2006

Bad Code Spotter's Guide

I hope many of the readers here know about this great informative site called "informit.com" which provides a virtual library where you can literally browse books and read a lot of them too. That apart, it carries wonderfully researched articles that I find very enlightening.


informit.com

A few weeks back, there was this article called "10 things I hate about UNIX" (printer friendly format) which really opened my eyes to new perspectives in our choice of OS in business situations. And this time, "Bad Code Spotter's Guide" (printer friendly view) has been showcased. Read it and you are sure to come back enlightened, unless you know a few other bad coding spots.

I specifically loved the paragraph on "Gratuitously Complicated Design". I remember instances where I have looked at previously written code that were needlessly complex. In such instances, I advise you should try finding out about the author of the code. Little known trivia about the author will help you understand why he wrote such a code. In the code that I was checking out, the author had needlessly used linked lists where small arrays could have done the job. It seems that the author, a contractor in the project, wanted to learn about linked lists and implemented linked lists to prove his capability! How's that?

There was this book called "Bitter Java" which highlighted those aspects of programming that usually get unnoticed. Bugs that creep in unnoticed to our "trained" eyes. Like the classic "try-catch-throw" problems or the "double-if-whammy". Back in 2000, I remember from a session that I attended where the class leader mentioned that he always included the parenthesis together to avoid missing the closing parenthesis. As in - you type '(' and immediately follow it up with another ')' before pressing a back arrow and typing what you want inside the parenthesis. That is something that I did catch on then and have not left it till date. I simply know that I do not miss a parenthesis in my code.

These are the true "Lessons Learnt" that we all can use for our advantage. Afterall, nobody did reinvent the wheel. Or did they? :-)

0 Comments:

Post a Comment

<< Home