gpt4 book ai didi

java - 我的代码的每个部分真的都需要 JavaDoc/Comments 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:58 24 4
gpt4 key购买 nike

<分区>

我正在为我在 uni 的最后一年 CS 本科项目编写一个 Java 应用程序。在前几年,我们被告知必须对我们的代码使用 CheckStyle。但是,我发现使用默认的 CheckStyle 配置需要我为每件事编写一个 JavaDoc。即使是名称和实际代码足以描述那段代码的作用的明显实例字段和方法,也需要我编写 JavaDoc 注释。

老实说,我发现这是重复的,只会让我的代码困惑。如果没有所有这些评论,我会发现我的代码更具可读性和更短,这让我在需要查看类等时可以更好地了解。

问题是,如果 checkstyle 将它突出显示为一个问题(缺少 JavaDoc)并且我们被告知毫无异常(exception)地使用 CheckStyle,那么我怀疑我会失去分数,这是我最不想看到的。我引用这本优秀的书:马丁·罗伯特·C. (2008-08-01)。清洁代码:敏捷软件工艺手册(第 54 页)。培生教育(美国)。

The proper use of comments is to compensate for our failure to express ourself in code. Note that I used the word failure. I meant it. Comments are always failures. We must have them because we cannot always figure out how to express ourselves without them, but their use is not a cause for celebration. So when you find yourself in a position where you need to write a comment, think it through and see whether there isn’t some way to turn the tables and express yourself in code. Every time you express yourself in code, you should pat yourself on the back. Every time you write a comment, you should grimace and feel the failure of your ability of expression. Why am I so down on comments? Because they lie. Not always, and not intentionally, but too often. The older a comment is, and the farther away it is from the code it describes, the more likely it is to be just plain wrong. The reason is simple. Programmers can’t realistically maintain them.

我不能说我是多么全心全意地同意上述观点。这些评论在我眼里只是一团糟。在相关的地方,我有意见。

所以,我的问题归结为以下几点:我应该坚持自己的信念和阅读上述书籍获得的知识/建议,还是应该遵守 CheckStyle 标准并消除因缺乏而被打分的风险JavaDoc 评论?

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