"Murphy was an optimist!"
Today’s Programming Advice – Code for the impossible May 14, 2009 12:26 pmPosted by Doug McCaughan in : Programming, Quality Assurance, Technology
Right now I am dealing with some code that involves a list of 1 or more items. The actionable part of the code involves clicking on one of the items in the list therefore at least 1 item must exist. Having zero items is impossible because if there were no items then I could not click on the item to start the actionable part of the code. So why waste time coding of the zero items case? This is not the best example since this is a multi-user, client/server web application and the zero case can be created quite simply by having two users pull up the same list and then one user deletes an item before the other. But that answers the question of why waste time coding for the impossible? Because it does happen. My code frequently has conditional statements that end with a default case or a special case that simply outputs "This is impossible. Please contact the administrator." and includes some debugging information. In my career, doing this has saved me hours and hours of debugging time on more than a couple of occasions.trackback