I don't mean to sound patronizing, but if you're implementing counters or banging out numbingly-boilerplate business logic for websites, comments are indeed useless. But when you're reading an obtuse 50-line function that implements some weird algorithm acting on some weird data structure, full of magic-like assumptions, you'd wish no one had deleted comments from it, or... had written them in the first place.
I hate comments
11–20 of 55 posts
Re: I hate comments
#12Hopefully no one even moderately unfamiliar with the language the code is written in needs to find out how to fix something that is broken. Citing breaking code by using some global that makes the comment no longer true? Sounds like an abuse of globals or someone not cleaning up the comments, not the comments themselves. So many times I have had to repair code in languages I wasn't quite familiar in or that was simpl…
I would consider that comment just as bad as the ones in my examples, but maybe not quite as obviously so.
Re: I hate comments
#13Why is the counter =0? Comments explain why your assertions are reality. Not every assertion is going to be as obvious as "balances have to be positive". If I had a dollar for every opaque assertion I blew up or ran into in code that had no explanation as to why something had to not be 0 or >1mil or null or whatever I would be a rich man.
Re: I hate comments
#14Hopefully no one even moderately unfamiliar with the language the code is written in needs to find out how to fix something that is broken. Citing breaking code by using some global that makes the comment no longer true? Sounds like an abuse of globals or someone not cleaning up the comments, not the comments themselves. So many times I have had to repair code in languages I wasn't quite familiar in or that was simpl…
"This method takes a foo object, applies HTML encoding, and returns an array of the original and the clean code." could be a 3-line unit test that's just as clear to read, but has the side effect of actually being true instead of maybe being true! I would consider that comment just as bad as the ones in my examples, but maybe not quite as obviously so.
Re: I hate comments
#15Hopefully no one even moderately unfamiliar with the language the code is written in needs to find out how to fix something that is broken. Citing breaking code by using some global that makes the comment no longer true? Sounds like an abuse of globals or someone not cleaning up the comments, not the comments themselves. So many times I have had to repair code in languages I wasn't quite familiar in or that was simpl…
"This method takes a foo object, applies HTML encoding, and returns an array of the original and the clean code." could be a 3-line unit test that's just as clear to read, but has the side effect of actually being true instead of maybe being true! I would consider that comment just as bad as the ones in my examples, but maybe not quite as obviously so.
Re: I hate comments
#16Also, sometimes the code is sufficiently brain-compiled that it's utterly inscrutable. Early in my career I wrote a fast interrupt driver for the company's main product that had become quite heavily optimized, and practically every line depended on nuances of the related hardware's functionality. This code was written in two-column code/comment form, and had more lines of comments than lines of code. This was necessary for it to be at all maintainable. In theory, a later refactoring might have simplified this state of affairs... but that opportunity never happened.
Re: I hate comments
#171) Why the code is doing what it's doing. What's the motivation? Why is a check necessary? What's the context?
2) High-level overview. 20 lines of code may speak for themselves, but a quick sentence can easily summarize it. I love well-summarized code. "Do X with the Y unless it's Z" is a really fast read. (Function names obviously provide this sort of explanation, but sometimes a name is not obviously not always sufficient.)
3) Stubs / future notes. Sometimes you need to leave something stubbed out. If you have thoughts on what they code will need to be, leave a note about it. This is easily removed later.
4) Quirks. If the code does something that is not obvious, note that. Non-obvious side-effects, bugs, etc. Don't discover something painful, then leave the next person (possibly a future you) to re-learn that same painful lesson.
Code does stuff. Comments describe the code. Comments should not re-describe what the code does, they should be about the code and the code's context itself.
Re: I hate comments
#18Hopefully no one even moderately unfamiliar with the language the code is written in needs to find out how to fix something that is broken. Citing breaking code by using some global that makes the comment no longer true? Sounds like an abuse of globals or someone not cleaning up the comments, not the comments themselves. So many times I have had to repair code in languages I wasn't quite familiar in or that was simpl…
Re: I hate comments
#19Hopefully no one even moderately unfamiliar with the language the code is written in needs to find out how to fix something that is broken. Citing breaking code by using some global that makes the comment no longer true? Sounds like an abuse of globals or someone not cleaning up the comments, not the comments themselves. So many times I have had to repair code in languages I wasn't quite familiar in or that was simpl…
def clean(foo)
return [foo, foo.apply_html_encoding]
end
The encoding logic should be contained in apply_html_encoding. The point is that most of the functions/methods that are 65 lines long are badly coded.