Failing early

November 27th, 2007

When coding it’s generally a good idea to fail early. Preferably at compile time. Today I found a little piece of code in an example that showed how to do just that. Not only that but I was also reminded of just days ago when I failed to follow that advise and was forced to search quite extensively for the bug I’d introduced. The following quote is from this page.

$musictype = ('jazz' == $music) ? 'cool' : 'blah';

Another important point in the above example, when doing logical comparisons always put the variable on the right side, like above. If you forget an equal sign it’ll throw a parse error instead of just evaluating true and executing the statement. It really takes no extra time to do, so if this saves one bug it’s worth it.

This really is a wonderful piece of advice. Just by placing the constant before the comparison you automatically detect when you fail to write double equal signs.

Potential-Power times Ease-of-Use equals Real-Power

June 21st, 2007

Browser wanted

June 13th, 2007


April 13th, 2007

Amish programmers

February 9th, 2007

Spam filters, don’t we just love them

January 26th, 2007


August 16th, 2006

Directory Submission Form Filling Tool

August 8th, 2006

Please prove me wrong about Java

July 7th, 2006

Quick CSS removal

July 6th, 2006