| The Worst Programming Advice I've Ever Received Thursday, May 07, 2020  may not need a comment.  I'd even agree, of course, that this would be an example of a "bad" comment:  When you start getting closer and closer to the machine's level with the code, however,
the importance of comments should be plainly obvious:  I don't know about you, but I'd personally be really thankful for that comment.
Unless I happened to remember all of those registers and interrupts, I'd be searching through
docs (anyone remember Ralf Brown's interrupt list?) for these details.
I'll take the comment any day!  And even if the comment were wrong and the code was actually setting 320x240
mode instead of 320x200, I'd still have more of a clue as to what the code was doing than I would without the comment.
In fact, it should be apparent that the further the code is from natural human language, the
more important that comments become.  This is also why commenting something like a complex
calculation is critically important.
Some organizations have PR (pull request) policies that require comments
be removed for the PR to be approved.  Honestly, I find this crazy.  Like everything
else, being pragmatic and practical is always a balancing act, but
I would much rather look at code that has a comment – even if the comment
is just a block of old code – than no comment at all, especially if the code
is complex.
Even the old code itself provides value here, whether on the intent, the
thought process that was gone through to the get the code to its
current state, etc.
In fairness, one thing that I am not a proponent of is what I call
"chicken commenting".  This is when a developer finds a block of code they
think they need to change – but they're not quite sure – so they
duplicate the block, comment out the original, and then poke changes at
the code.
Doing so can almost be understandable at times.  I once worked
with a large VB6 project (which used .zip files for version control) that had gone through so many hands, no one
really knew what the code did anymore, so to avoid breaking things,
blocks of the original code were routinely commented out and duplicated to provide
something to fall back to in the event that any changes made didn't work.
Unfortunately, the commented-out code blocks were rarely removed, even when the changes worked.
This I consider an inappropriate use of comments,
especially when done to excess.
At the end of the day, however, like most everything else in software, it's all a balancing act.
In the same way that I feel that making a blanket statement like "boolean
parameters are evil" is rather arbitrary, I feel that saying that
code shouldn't be commented or that comments shouldn't be in production,
master-branch code is equally arbitrary.
There's generally an understanding that all code has bugs (even when it compiles, of course).
With this in mind, avoiding comments simply because they're not checked/compiled doesn't make much sense.  Successfully-compiling code only indicates
lexical and semantic correctness; it says nothing about logical correctness.
This is another bridge that comments help to provide: "Does the intent match the
design?"
Source code is holistic, and trying to limit it to simply machine-operable
instructions does no one any favors – especially the next developers in line
who inherit that code.  If you're not big on commenting your code, I'd encourage you to give it
another shot.  Your fellow devs – and maybe even your future self – will probably thank you for it. | ||||