lundi 27 juillet 2015

Software Engineering: Conditionals evaluate "good" or "bad" order [duplicate]

This question already has an answer here:

I remember reading in a software engineering book once that there is a typical rule to follow when writing if else conditional statements as to the order of evaluation. Should the valid case be evaluated first then followed by the invalid/erroneous case or vice versa? Is there a proper order for which cases should be evaluated first?

Example:

if (good) {
    // Exec some block of code for good case.
} else {
    // Bad case.
}

or

if (errorCase1) {
    // errorCase1 block.
} else if (errorCase2) {
    // errorCase2 block.
} else {
    // good case.
}

Aucun commentaire:

Enregistrer un commentaire