/* Dear Maintainer,
* I write the following in the sincere hope that
* it sorts the variables a, b and c in ascending order.
*/
if (a > b) swap(a, b);
if (b > c) swap(b, c);
They are useful when the code is complicated and the intent is not obvious. Or when there can be multiple plausible intents based on what the requirements are. Sometimes code contains implementations of requirements that are not spelled out in any requirements document. A high level requirement can break down into lower-level ones in umpteen ways. Whatever isn't in the detailed design document is only in the comments and the code. A programmer's statement of intent can in fact be a requirement specification: the only such document for that piece of code.Beware the Siren Song of Comments
11–20 of 34 posts
Re: Beware the Siren Song of Comments
#12My teams find more and more value from documentation as they are forced to return to code months/years later.
And commit logs as the place to document performance issues? Seems like an easy way to make sure that a "weird" bit of code gets removed, and breaking your app.
As with all things, ideologies and blanket statements suck. I think what was talked about in this article could've been much better communicated if it wasn't so polarizing.
I've found comments are only not added or updated when people feel rushed. Or a culture which doesn't put value in them... Which is a problem with one's organization not the act of writing comments.
P.s. This is an edit: isn't it rather peculiar someone tasked with annotating all text doesn't annotate their code? Irony?
Re: Beware the Siren Song of Comments
#13"Comments decay. They aren’t compiled, and they’ll never get executed at runtime. If they become out of date or incorrect, no test is going to fail and no user is going to complain. Programmers work around them out of fear that “somebody might need this comment or it might provide some value in the future”, pushing them along far after they’re useful" The developers who say this are ticking time bombs of laziness on…
...at Genius.
Re: Beware the Siren Song of Comments
#142nd Point: Explain performance hacks in commit description | might was well not explain them at all. This is a great place to hide the reason for the performance hack
3rd point: Don't use TODO / FIXME | I'm on the fence.
4th Point: Don't comment out old code use version control for old stuff | Ok
Re: Beware the Siren Song of Comments
#15And to some extent some comments do decay. However, with experience, we learn to write comments with a minimal decay profile. As an example, avoid including constants in comments. Also, if you find yourself writing the same text over and over again, it's a sign you're being too redundant and can elevate that comment to a high level.
Re: Beware the Siren Song of Comments
#16> The right place to document [performance] hacks is a commit message. This advice strikes me as patently insane. Serious performance hacks often involve subtle interactions among different parts of the code. When that happens, properly documenting them requires explaining what's going on in a line of code, for every line of code, right next to that line of code. Just sticking a wall of text somewhere else entirely a…
Re: Beware the Siren Song of Comments
#17You "only" need to remember that the method is named reslug_all_tag_pages.
Re: Beware the Siren Song of Comments
#18"Comments decay. They aren’t compiled, and they’ll never get executed at runtime. If they become out of date or incorrect, no test is going to fail and no user is going to complain. Programmers work around them out of fear that “somebody might need this comment or it might provide some value in the future”, pushing them along far after they’re useful" The developers who say this are ticking time bombs of laziness on…
Comment decay is a rehash of "code that isn't written is never incorrect". Aka every change you make introduces an opportunity to make a mistake, including both writing and updating comments.
Re: Beware the Siren Song of Comments
#19When I see something like,
42 def wobble(self):
43 # Make sure the vent core has been frog-blasted,
44 # so that we know {rare bad things} won't happen
45 frog_blast(self.vent_core)
46 self.do_important_things()
I find that a much faster answer to "Do I really need to foo the bar?" than if I have to decode it: 42 def wobble(self):
43 frog_blast(self.vent_core) # see commit msg
44 self.do_important_things()
git blame wobble.py
git log abcd4242
Author: Bob
Ensure that vent core is properly blasted
We rarely have frogs, but the vent core must be cleared.
Is this a matter of insufficient knowledge of my IDE? (I'd love to be able to easily show the last commit messages for specific lines in a tooltip or other popup.) Having to context-switch into commit-sleuth mode seems (to me) to be more disruptive than having the code comment.Re: Beware the Siren Song of Comments
#20> The right place to document [performance] hacks is a commit message. This advice strikes me as patently insane. Serious performance hacks often involve subtle interactions among different parts of the code. When that happens, properly documenting them requires explaining what's going on in a line of code, for every line of code, right next to that line of code. Just sticking a wall of text somewhere else entirely a…
Likely to be using a workflow that uses `git blame` or equivalent to understand the context of code. The problem that is intended to fix is that comments don't stay in sync with the code they're commenting about. The problem it introduces is discoverability. You have to search to see where this code came from in order to understand it. That isn't going to happen unless you're disciplined. And we're all undisciplined…