If statements in code, need I say more. I know most of you out there get it (and yes, if statements are not the only way to branch code, but they are the worst offender IMHO). I just seem to be lucky enough to continue to find code riddled with if statements. Why don’t these people get a clue, if is evil. Do the math, for every if statement you create two distinct code paths. Using just 8 if statements in a method yields 256 possible ways it can behave (or misbehave).

Next time you see yourself tying the keyword if, ask yourself “is this really the right way forward?”. I’m a huge proponent that some code, for some purposes, just doesn’t deserve the effort. If your writing code that is going out the door, especially in a user-interface, do yourself a favor. Find a better solution, there are loads of OO patters that can answer this easily. Pick one…

For those confused about why I would call attention to user-interface code in particular there is an easy answer. It is often the least tested part of your application (usually requiring human involvement). This is one of many reasons for MVC and other patterns that move the code out of the UI.

As an additional side-note, I blame the current lack of design in UI code on Microsoft and their pointy-clicky IDE. I know, I know, we as an industry (at least here in the states) are trying to fix it. It doesn’t really matter though. There are still millions of lines of poor code being written by junior developers. Before I go off on a tangent about over-seas development I’ll drop this issue… for now.

One last question for you, Which of the following do you think is the most evil?

  • if
  • while
  • for
  • set
  • break/continue
  • public
  • event

 
Click here to post your ideas on what is the worst (most abused) keyword.

Comments