Saturday, May 26, 2007

if statements

Method 1:

if(isTrue())
doSomething()


<--- identical --->
Method 2:

if(isTrue())
{
doSomething()
}

Me being the bad programmer, found myself debugging for a looonnnnggg time over a very stupid mistake made from the above convenience.

I used the first method somewhere in the thick jungle of my code. After some weeks, i decided to add some operation that would do another thing before the doSomething() function, along with many other changes.

As you might have guessed, i forgot the braces, and what happens next is an hour of scratching head and tearing of hair. :)
I felt like giving myself a tight slap when i found out why my code did not work as expected.

No comments: