Hacker News new | past | comments | ask | show | jobs | submit login

I feel that marking a hack is one of the few legitimate uses for comments in code

I'll take that as an offhand comment you didn't give much thought to, because wow, there most certainly are lots of legitimate uses for comments in code.




I'm pretty firmly in the "code as documentation" camp, what can I say? I think that most of the time, if you can describe an action with two or three words, you probably ought to be extracting that logic into a method by the same name.

IMHO comments are best used in a handful of situations, such as:

1) Marking hacks 2) Explaining unusual, non-obvious sections of code 3) Noting historical reasons for doing something in a non-obvious manner 4) Noting pitfalls to be avoided 5) Making passive aggressive remarks about the "business guy" who made you do something terrible

Not an exhaustive list of course, but I do think that it's best to think twice before writing a comment, asking yourself "how can I make this more obvious with my code?"




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: