第二人或第三人评论?

发布于 2024-08-09 18:06:46 字数 199 浏览 3 评论 0原文

你用第二人称还是第三人称写评论?

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦太阳 2024-08-16 18:06:46

我经常倾向于用医生风格说话:

// Now we take $x and check whether it's valid for this pass

I often tend to speak doctor style:

// Now we take $x and check whether it's valid for this pass
流心雨 2024-08-16 18:06:46

绝对是第三人称风格。

Definitely 3rd person style.

痕至 2024-08-16 18:06:46

一个有用的提示:尝试使每条评论尽可能独立。例如,这种形式:

// First, mumble the frabbitz.

blah blah

// Second, foobar the quux

blah blah

这是一个很好的叙述,但使编辑代码变得更加困难,因为“第一”和“第二”部分可能会变得不正确。最后,他们并没有在评论中添加太多内容,而是使它们以脆弱的方式相互关联。

One helpful tip: try to keep each comment as self-contained as possible. For example, this form:

// First, mumble the frabbitz.

blah blah

// Second, foobar the quux

blah blah

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.

薄荷港 2024-08-16 18:06:46

我的观点是,你应该使用你觉得最舒服的任何风格。

嵌入式注释旨在供您和其他试图了解代码实现细节的开发人员阅读。只要它们清晰易懂,即使它们的风格有点不寻常、语法有点差或者有一些拼写错误也没关系。正在阅读它的人应该不关心这些事情。

提取形成 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.

紫瑟鸿黎 2024-08-16 18:06:46

我有时会用第一人称说话,就像这样

/*
Usage:  
set_position(0.5, 0.5);  // im in the center
set_position(0.0, 1.0);  // im in the lower,left corner
*/

I sometimes speak in 1st person, like this

/*
Usage:  
set_position(0.5, 0.5);  // im in the center
set_position(0.0, 1.0);  // im in the lower,left corner
*/
怂人 2024-08-16 18:06:46

这可能取决于有多少人正在编辑代码以及编辑代码的目的。在我自己的代码中(但仍供公众查看),我可以随意添加一些个人评论,也许可以使用“我”。在公共项目中,评论应该针对公共风格,“我”可能不合适。

请注意,注释很脆弱,许多现代权威(例如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文