gpt4 book ai didi

java - Sonar 、Java 和 'trailing comment' 违规

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:29:10 25 4
gpt4 key购买 nike

在我的一个项目上运行 Sonar 后,我收到了“尾随评论”的违规通知。所以我想知道,这是否纯粹与 Java 接受/推荐的代码布局约定有关,还是“更多”?其背后的原因是什么?当我查看一些 C++ 代码(最近的 Doom code review 时,有大量(或充满 Binder 的)尾随注释。

最佳答案

来自名著代码大全:

  • The comments have to be aligned so that they do not interfere with the visual structure of the code. If you don't align them neatly, they'll make your listing look like it's been through a washing machine.

  • Endline comments tend to be hard to format. It takes time to align them. Such time is not spent learning more about the code; it's dedicated solely to the tedious task of pressing the spacebar or tab key.

  • Endline comments are also hard to maintain. If the code on any line containing an endline comment grows, it bumps the comment farther out, and all the other endline comments will have to bumped out to match. Styles that are hard to maintain aren't maintained.

  • Endline comments also tend to be cryptic. The right side of the line doesn't offer much room and the desire to keep the comment on one line means the comment must be short. Work then goes into making the line as short as possible instead of as clear as possible. The comment usually ends up as cryptic as possible.

  • A systemic problem with endline comments is that it's hard to write a meaningful comment for one line of code. Most endline comments just repeat the line of code, which hurts more than it helps.

话虽如此,这也与一个人对编码风格的选择有关。我个人会避免尾随评论,因为它们对帮助不大。

关于java - Sonar 、Java 和 'trailing comment' 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14385476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com