felixge / felixge/node-style-guide

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

Abierto
#95 2 comentarios 3 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
5k
Forks
893
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

"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 *********************
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.