Thursday, November 03, 2005

Coding up that if/else

Something that really irks me in code is when I see something like this:

if (result == FAILED)
print "failed!\n";
return;
else
// do whatever
end


You don't need the "else"! If the "if" statement evaluated to be true, then there's no reason why it would jump out of it. Therefore, there's no reason that the //do whatever part of the code should be inset! Do this a couple times, and you'll have a nightmare of nested code. Keep your code as shallow as possible. Don't nest if you don't have to.

No comments:

Post a Comment