TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Don't use comments, use code

9 点作者 tekkertje超过 3 年前

3 条评论

theamk超过 3 年前
It is tackled at the very end of the article, but there is a very good and a totally valid use of the comments: answering &quot;why?&quot; questions (as opposed as describing the code).<p>This propagates to all other advice in this article.<p>Magic numbers? Comments can be good be useful if they answer &quot;why&quot;<p><pre><code> PACKET_SIZE = 32 # Section 3.5.7 of RFC-99999 </code></pre> TODOs? Comments can be good if they answer &quot;why&quot; (as in, &quot;why haven&#x27;t this been done yet)<p><pre><code> # TODO: once #1234 is fixed, rewrite as a binary search (right now it is not supported) </code></pre> After-update notes? If the action is optional, make it a comment -- this will make upgrading to latest version easier.<p><pre><code> # This function is present in libfoo-1.23, but our version is older, so we are re-implementing it here.</code></pre>
评论 #28408300 未加载
评论 #28408599 未加载
terracottage超过 3 年前
People who think comments are a code smell have generally never had to go back to a codebase they haven&#x27;t touched in 3-6 months.<p>This cures all illusions.
MathMonkeyMan超过 3 年前
Comment everything. The worst thing that can happen is somebody concludes &quot;nope, that&#x27;s not true anymore.&quot; To avoid describing the system entirely is nothing but laziness. Rationalize it however you like, it&#x27;s just laziness.