第二人或第三人评论?
你用第二人称还是第三人称写评论?
// go somewhere and do something (2nd person comment)
或者
// goes somewhere and does something (3rd person comment)
Do you write comments in 2nd or 3rd person?
// go somewhere and do something (2nd person comment)
or
// goes somewhere and does something (3rd person comment)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我经常倾向于用医生风格说话:
I often tend to speak doctor style:
绝对是第三人称风格。
Definitely 3rd person style.
一个有用的提示:尝试使每条评论尽可能独立。例如,这种形式:
这是一个很好的叙述,但使编辑代码变得更加困难,因为“第一”和“第二”部分可能会变得不正确。最后,他们并没有在评论中添加太多内容,而是使它们以脆弱的方式相互关联。
One helpful tip: try to keep each comment as self-contained as possible. For example, this form:
this is a nice narrative, but makes it harder to edit the code, because the "First" and "Second" parts may become incorrect. In the end, they don't add that much to the comments, but make them interrelated in a fragile way.
我的观点是,你应该使用你觉得最舒服的任何风格。
嵌入式注释旨在供您和其他试图了解代码实现细节的开发人员阅读。只要它们清晰易懂,即使它们的风格有点不寻常、语法有点差或者有一些拼写错误也没关系。正在阅读它的人应该不关心这些事情。
提取形成 API 文档的注释值得更多地关注风格、语法和拼写的细节。但即使在这里,准确性和完整性也更为重要。
My view is that you should just use whatever style you feel most comfortable with.
Embedded comments are intended to be read by you and other developers trying to understand the implementation details of your code. So long as they are clear and intelligible, it does matter if they style is a bit unusual, the grammar is a bit poor, or there are a few spelling errors. The folks who are reading it should be beyond caring about such things.
Comments that are extracted to form API documentation deserve a bit more attention to the niceties of style, grammar and spelling. But even here accuracy and completeness are far more important.
我有时会用第一人称说话,就像这样
I sometimes speak in 1st person, like this
这可能取决于有多少人正在编辑代码以及编辑代码的目的。在我自己的代码中(但仍供公众查看),我可以随意添加一些个人评论,也许可以使用“我”。在公共项目中,评论应该针对公共风格,“我”可能不合适。
请注意,注释很脆弱,许多现代权威(例如 Clean Code)建议函数和字段应该带有有意义的名称。但是,当然,在很多地方解释性评论仍然至关重要。
It may depend on how many people are editing the code and for what purpose. In my own code (which is nevertheless for public view) I may feel free to add some personal comments, perhaps using 'I'. In a communal project the comments should aim at a communal style and 'I' may be out of place.
Note that comments are fragile and many modern authorities (e.g. Clean Code) suggest that functions and fields should carry meaningful names. But, of course, there are many places where explanatory comments are still vital.