Skip to content


The Naked Else – How I Hate Thee

I cannot express my frustration at seeing code like this:

if (isset($modifier)) {
    // Do some things.

    // And some more things.

    // Still more
    // things
    // to be done here.

    // There's a whole lot of things here!

    // Last bunch of things
}
else {
    // Do totally different stuff
}

People. Comment your elses! I shouldn’t have to scroll up to read the if again just to figure out what a branch of logic does. This is a maintenance code nightmare, and simply adding a simple “// If validation has failed” will save all kinds of time and frustration.

Posted in Coding.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.