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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Comments In Code

7 点作者 hamedh超过 13 年前

7 条评论

DrPppr242超过 13 年前
I signed up for an account just to say I strongly disagree with this. I'm a sys admin who doesn't spend all day writing code, and certainly doesn't know all the common idioms associated with different languages. Leaving a comment about in the code about something that's not obvious to some one who doesn't code in perl/ruby/php (or whatever you're using) but if familiar with common programming concepts is beyond useful to someone like me.
jcmhn超过 13 年前
Why I comment:<p>When I'm learning a language I write comments for myself. Notes about syntax, idioms, gotchas, and whatever else.<p>When I'm fixing a problem I leave XXX markers around to easily keep track of what I'm doing.<p>When I'm writing maintenance code I reference the ticket number, describe the problem or feature, and why we implemented the fix or feature the way we did.<p>You should never see the first two types of comments in checked in code, but I bet that I've probably saved later maintenance programmers hours of frustration with that last type of comment.
chrisledet超过 13 年前
I'll just leave this here: <a href="http://zachholman.com/posts/documentation/" rel="nofollow">http://zachholman.com/posts/documentation/</a>
评论 #3140274 未加载
beaumartinez超过 13 年前
Comments and readable code aren't mutually exclusive.<p>&#62; <i>Code should be almost as readable as a book. You should be to read without pausing too much as well as skimming.</i><p>I pause much more reading code than I do reading prose.<p>Trying to keep a lookup table of functions and variables in my head is much harder than reading a few lines of prose to let me know what's going on.<p>Comments should summarise what's going on, so that when you have a bug, you can jump to the right section to change.<p>&#62; <i>Comments are almost like an annotation in a book. So use them sparingly.</i><p>The way I think of it: Don't use comments to annotate your code. Use code to annotate your comments.
gordonguthrie超过 13 年前
I agree - it is the old principle of least surprise. You should use comments when the code reader would be surprised...<p>Sometimes you <i>have to</i> do bad stuff and you should stick a comment in there so that when you come back to that bit in code you are forewarned...<p>Think of it as <i>hic seunt leones</i> on old maps (here be lions for all the non-latin speakers out there...)
baggachipz超过 13 年前
Don't like my comments in my code? Don't read 'em. They're useful to some people.
ascendant超过 13 年前
This discussion is one that will never die because people will always have entrenched, dogmatic viewpoints on this. I dislike comments that explain what you're doing. The code should be readable enough to see what you're doing. However having spent over a decade now maintaining code written by people that may not be with the organization anymore, it's always nice to occasionally get context on WHY someone wrote the code they did. Odd bugs and subsequent workarounds, weird client requirements, etc. I've spent many hours trying to figure out why someone did something because they're not around anymore to ask. We can go on and on about the purity of code and how readable it should be but no amount of concise code can replace "did this because of client requirement X,Y and Z" right there so I don't have to go hunting to find out. The gulf between how things SHOULD be and how they ACTUALLY are is pretty wide in my experience.
评论 #3140767 未加载