如何将常规评论分成段落,同时让 StyleCop 满意?

发布于 2024-09-13 08:50:34 字数 1048 浏览 12 评论 0原文

有时需要冗长的评论。当存在需要长时间解释的丑陋黑客时,可能会发生这种情况。是的,最好完全避免/修复黑客攻击,但通常存在时间压力,必须将其推迟到未来。如果是这样的话,那么详细的评论是非常有帮助的,包括那些想要用更好的代码替换 hack 的人。关键是确保他们准确理解黑客正在做什么以及为什么。

通常这需要多个段落。如果允许诸如 // 之类的空白注释,则注释将更具可读性。然而,StyleCop 不喜欢这些,我们总体上同意它,所以我们尝试坚持它的所有建议。现在,我可以想到三个选项:(

//// This is a hack ...
//// ..................
//// 
//// When fixing this hack make sure ...
//// ...................................

我不喜欢第一个,因为我通常使用双/三/四注释来注释代码部分)。

// This is a hack ...
// ..................
////                                   <== This will slide, but I think it looks dumb. 
// When fixing this hack make sure ...
// ...................................

(我不喜欢第二个选项;我认为它看起来有点愚蠢)

// <para>
// This is a hack ...
// ..................
// </para>
// <para>
// When fixing this hack make sure ...
// ...................................
// </para>

(我也不喜欢第三个选项。它非常适合 /// 方法文档,但这里看起来有点不合适,

请提出更好的方法。

Sometimes there is a need for lengthy comments. This can happen when there is a fugly hack which needs long explanation. Yes, it is better to avoid/fix the hack altogether, but often there is time pressure and one has to push it off into the future. If that is the case, then having a detailed comment is quite helpful, including those who would be replacing a hack with better code. The key would be making sure that they understand exactly what the hack is doing and why.

Often that requires multiple paragraphs. The comment would be more readable if blank comments such as // were allowed. However, StyleCop does not like those, and we agree with it overall, so we try to stick with all of its suggestions. Now, i can think of three options:

//// This is a hack ...
//// ..................
//// 
//// When fixing this hack make sure ...
//// ...................................

(I do not like the first one because I generally use double/triple/quadruple comments for commenting out sections of code).

// This is a hack ...
// ..................
////                                   <== This will slide, but I think it looks dumb. 
// When fixing this hack make sure ...
// ...................................

(I do not like the second option; I think it looks sort of dumb)

// <para>
// This is a hack ...
// ..................
// </para>
// <para>
// When fixing this hack make sure ...
// ...................................
// </para>

(I do not love the third option either. It is well-suited for /// method documentation, but here it looks sort of out-of-place.

Please suggest a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

萌梦深 2024-09-20 08:50:34

/*
每当我要发表冗长的评论时,无论原因如何,我都会使用“slashterix”“块评论”风格。

总是对我有用。
YMMV,但这是我最好的建议。 8)
*/

/*
Any time I've got a lengthy comment to make, regardless of cause, I use the "slashterix" 'block comment' style.

Always works for me.
YMMV, but it's my best suggestion. 8 )
*/

蓬勃野心 2024-09-20 08:50:34

为什么不直接使用换行符呢?

// Some comment
// Some comment

// Some more comments
// Some more comments

// Yet more comments
// Yet more comments
int x = 2;

Why not just use linebreaks?

// Some comment
// Some comment

// Some more comments
// Some more comments

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