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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: What if code comments were not supported?

2 点作者 klhugo超过 3 年前
Crazy idea here :)<p>The better I get at writing clean code, the less comments I need to use. What if there was a &quot;compiler mode&quot; where comments were forbidden. Or maybe you are entitled to a limited number of comment words per file.<p>Could that spur programmers to write better code?

6 条评论

codegeek超过 3 年前
Good code should have some comments. Not for the &quot;what&quot; but for the &quot;why&quot;.
评论 #28859277 未加载
eyelidlessness超过 3 年前
I had some thoughts on this just a couple weeks ago, in which I outright said I think most code comments are harmful: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;eyelidlessness&#x2F;status&#x2F;1444096909136654341?s=21" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;eyelidlessness&#x2F;status&#x2F;144409690913665434...</a><p>That said, I don’t think barring comments would be helpful. As you described, presence&#x2F;frequency of comments tends to diminish as code quality improves. More, clarifying what I put in the tweet thread: quality of comments tends to improve and reliance on low quality comments tends to drop.<p>But that’s a correlation with other positive factors. Enforcing that a hypothetical low quality code author cannot include comments won’t convey all of the other factors that would help them improve the code they write. It’ll just make their low quality code more opaque.<p>A better approach, in my opinion, is to treat comments as code smells in review&#x2F;maintenance tasks. You can use this as an opportunity to interrogate the comments directly, and discuss the commented code secondarily. This gives you a chance to express, <i>here’s an approach that might not need explanation at all</i>.
mathematically超过 3 年前
It would not because comments are not what prevents people from writing good code.
muzani超过 3 年前
My CS prof had a saying: Every comment is an apology.<p>Getting rid of apologies won&#x27;t prevent people from making mistakes. Sounds like a cure for the symptoms and not the source.
high_byte超过 3 年前
the answer is simple: nobody would use it.<p>like what if there was a pc that wouldn&#x27;t accept mice. I&#x27;m heavy hotkeys user and I wouldn&#x27;t give up my mouse.
kwertyoowiyop超过 3 年前
Just comment your dang code!<p>Seriously. Explain it at a level or two above the individual statements.