Friday, July 2, 2010

Another style pet peeve

Here is another pet peeve people might do when program:

if(A) {
    if(B) {
        somecode1();
    }
}

Who knows, it might not matter the compiler, but for human readability sakes never do this, there really shouldn't be an excuse. Maybe for when debugging but in that case clean it up before you show it to the world.

Just write it as this:

if(A && B) {
    somecode1();
}

please...

Ok, so why write it as the latter? Well Personally every time I see nested if statement I think there is a reason for the nesting. There could be code at the start of nesting or at the end of the nesting, I can't tell at first glance, I must pay attention to those details, which is not something I'm good at, it also takes more time to investigate which of the damn closed nesting statements corresponds to which. Plus with more nesting = more text on the screen = harder to read.

Just remember that reading other peoples code is one of the hardest thing for a programmer to do, so the more to the point the code is written, the easier it is to read and understand (the whole point of reading).

No comments:

Post a Comment