TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Comments Are a Code Smell (2019)

18 pointsby kugurerdem2 months ago

5 comments

cjs_ac2 months ago
The assertion that comments are a code smell assumes that the source of complexity in your codebase is either developer taste or some computer-sciency problem that becomes apparent to anyone reading the code in a few minutes or so. But sometimes the complexity is intrinsic to the problem you're solving; sometimes there's some quirk or edge case that means you can't do the obvious thing. In those circumstances, you need comments to explain what you're doing, how you're doing it, and why.
评论 #43375297 未加载
rhelz2 months ago
The code tells what the program actually does.<p>The comments tell what the program <i>should</i> do.<p>This distinction is so important that English marks it syntactically. Here&#x27;s an example of how this shakes out:<p>BAD: &#x2F;&#x2F; this routine takes its input, multiplies it by 9&#x2F;5, and then adds 32<p>Good &#x2F;&#x2F; this routine converts Celsius to Fahrenheit<p>Another example: is this code buggy? for(i=0;i&lt;=10;i++) { &#x2F;&#x2F; do something }<p>No way to know if you don&#x27;t know the programmer&#x27;s intensions, which is to say, if you don&#x27;t know what the code <i>should</i> do.
评论 #43375696 未加载
评论 #43377054 未加载
评论 #43375431 未加载
taylodl2 months ago
<i>&gt; Well, I dunno. I think the smell was there before you wrote the comments. The comments are febreze.</i><p>Awesome! I will never look at comments the same again!
bob10292 months ago
I use a lot of comments during development, but rarely keep them around in final production code. As features become stable, I tend to subconsciously delete them in the underlying areas.<p>My rationalization is that source control has already captured this history, and if someone really wanted to see what I was thinking, they could review the commit(s) for that file and get a perfect picture.<p>There are some places where I think comments should persist, such as where you expect future developers (yourself) will be breaking ground again for additional features. Things like &quot;TODO: New Components go here&quot; on a switch statement, or &quot;Review the following issue # for change process around this type&quot; located at the top of a very important piece of code.
评论 #43376470 未加载
Clamchop2 months ago
I&#x27;m not really sure what the takeaway is here. It&#x27;s not &quot;don&#x27;t write comments&quot; since that would not have helped the situation.<p>At the very least, if you&#x27;re going to write comments, bug reports, and code reviews, each one should be descriptive enough _on its own_. Not the right time for DRY! It is indeed irritating having to follow a thread across several places to get to the answer.