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";
// do whatever

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s