首页 > 网站 > WEB开发 > 正文

JavaScript Patterns 2.11 Writing Comments

2024-04-27 14:23:36
字体:
来源:转载
供稿:网友

javaScript Patterns 2.11 Writing Comments

2014-05-26 13:43 by 小郝(Kaibo Hao), ... 阅读, ... 评论, 收藏, 编辑

Document all functions, their arguments and return values, and also any interesting or unusual algorithm or technique. Think of the comments as hints to the future readers of the code; the readers need to understand what your code does without reading much more than just the comments and the function and PRoperty names. When you have, for example, five or six lines of code performing a specific task, the reader can skip the code details if you provide a one-line description describing the purpose of the code and why it’s there. There’s no hard and fast rule or ratio of comments-to-code; some pieces of code (think regular expressions) may actually require more comments than code.

The most important habit, yet hardest to follow, is to keep the comments up to date.


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表