jeudi 29 septembre 2016

Is there an advantage of non cuddled else (Stroustrup style) over cuddled else (1TBS style)?

I searched all the discussions and can't find what is the advantage of using this:

if (x < 0) {
    puts("Negative");
    negative(x);
}
else {
    puts("Non-negative");
    nonnegative(x);
}

over this:

if (x < 0) {
    puts("Negative");
    negative(x);
} else {
    puts("Non-negative");
    nonnegative(x);
}

Why isn't the second variant considered superior to the first? What are the advantages compared to the disadvantage of having 1 more line? Why is the 1st variant used in code, where you don't have to stick with 1st variant coding style?

I am uniform with my coding style, but this (and cuddled catch) is the last remaining problem for me in that area.

Aucun commentaire:

Enregistrer un commentaire