felixge / felixge/node-style-guide

Early return from a function is not always a good idea.

Ouverte
#95 2 commentaires 3 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
5k
Forks
893
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

"always return a function's value as early as possible"

I think you should put some caveats on this. Returns (and breaks and other break out statements) buried inside blocks of code are easily missed and are a very significant source of bugs on later modifications to the code (I speak with many years of experience).

For me returns should either be in the first few lines of the function (where some simple ifs deal with trivial cases) or in the last few lines of a function.

If one has to put a return in the middle of a longer function then I would make it stand out with a comment so it is not easily overlooked.
```
return; // ****************** RETURN *********************
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.