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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Don't comment your code. Refactor it.

4 点作者 mcrittenden超过 4 年前

3 条评论

jfengel超过 4 年前
The most important &quot;comments&quot; in your code are names. Taking a chunk of code and giving it a name gives you a small bit of free text to explain what it does. The function signature gives you a few more words to play with: foo(Bar x) -&gt; Baz is a function that foos a Bar into a Baz. (Another reason why functions should have as few arguments as you can manage.) A well-named piece of code will often read almost like natural language text.<p>People tend to ignore comments anyway. The fewer of them you have, the more likely they&#x27;ll take notice of one that&#x27;s actually important.
valand超过 4 年前
&gt; Explaining why the most obvious code wasn’t written. (Design decisions)<p>This is actually the most important thing in this article. The technical why of things are often overlooked in today&#x27;s software development. It rarely is the problem until the original maintainer moves out to other project. Non-technical contributor sometimes won&#x27;t or can&#x27;t be bothered with it because either it is pretty complex, they have a lot in their plates doing non-technical stuffs, or both.<p>While commenting on the what is DISCOURAGED because 1.) comments can be quickly outdated and they are not tested&#x2F;compiled 2.) they can be replaced with self-documenting code, commenting on the why must be ENCOURAGED, unless the software has a dedicated technical manuals &#x2F; design document, which is pretty rare these days.<p>&gt; The problem with comments is that they have no compile-time check and tend to be forgotten. It’s very easy to change your code but forget about the comments.<p>I write a bit of Rust and they have partial comment check on compile time. We can write example in the comments and they actually runs and get converted into a documentation. Neat!
mariaanton89超过 4 年前
agree...