felixge / felixge/node-style-guide

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

未关闭
#95 2 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
5k
派生
893
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。