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 In Code

7 pointsby hamedhover 13 years ago

7 comments

DrPppr242over 13 years ago
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.
jcmhnover 13 years ago
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.
chrisledetover 13 years ago
I'll just leave this here: <a href="http://zachholman.com/posts/documentation/" rel="nofollow">http://zachholman.com/posts/documentation/</a>
评论 #3140274 未加载
beaumartinezover 13 years ago
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.
gordonguthrieover 13 years ago
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...)
baggachipzover 13 years ago
Don't like my comments in my code? Don't read 'em. They're useful to some people.
ascendantover 13 years ago
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 未加载