3 ms·
As a code reviewer, I love seeing comments like that, because it immediately flags "someone made a mistake here". Sure, sometimes the code is right and the com
by cperciva 4y ago
As a code reviewer, I love seeing comments like that, because it immediately flags "someone made a mistake here".
Sure, sometimes the code is right and the comment is wrong -- but sometimes the comment is right and the code is wrong, in which case the comment just saved me a lot of time.
- layer8 4y agoAt the very least you know what the next likely alternative intended semantics is.
- SilasX 4y agoIt's also possible that both the comment and the code are right, and there's some non-obvious reason why +=2 has the effect of adding 1 here, and is the only way to do it. (Not literally, as in this example, but something analogous.)
- nextaccountic 4y agoI think it was Dijkstra that said that software actually lives in the mind of the programmer, and the code is just a distorted, lossy representation of that. Anything that gives us light on their thoughts is likely to improve our understanding of the software. Bugs happens when there's a mismatch between what's going on the mind of the programmer and what the code actually does, so when we read code a primary task is to understand what the programmer thought it should do. Comments informs us what are the stuff that the programmer cares enough to write down. When we see a seemingly trivial comment, we may ask: why did they took time to write down that? Did they think there was any subtlety we aren't aware of? Or perhaps they were inexperienced with the language, to the point of having a hard time reading the code they themselves wrote? (if I put this comment on Google, will I find they copy-pasted from Stack Overflow? -- in this case, the comment may be very helpful, if only to track down that [0]) [0] but even better would be an IDE that highlighted code copy-pasted from Stack Overflow, Github repositories, etc