mardi 26 juin 2018

Preferred Style for IF ELSE Statements Involving Return

I am curious what is typically better, in terms of readability and effeciency:

Option 1: Least indentation but slightly less clear flow

if (foo) {
   // do very little stuff
} else {
   // do other stuff
   return
}
// do stuff given foo must equal true to have reached here
return

OR

Option 2: More indentation but clearer flow

if (foo) {
    // do very little stuff
    // do stuff given foo must equal true to have reached here
    return
} else {
    // do other stuff
    // return
} 

I understand this question is quite broad, and may even have a different answer depending on enviorment, language etc. but I curious if there is any difference typically?

Aucun commentaire:

Enregistrer un commentaire