News for hackers. Stuff that matters.
Re:Reducing technical debt by valuing comments as much as code by lordgroff on Tuesday January 31, 2023 @05:53PM (#34603516)
So train people to write better comments, because although code doesn't lie (questionable as that is since the intent behind the code and what it does doesn't always align) it can be literally the worst implantation of an algorithm imaginable, and so we teach people how to code.

Teaching people how to comment is a skill that's just as important and nothing turns me off a project faster than the "code is its own documentation" mantra.

Re:Reducing technical debt by valuing comments as much as code by afarrell on Tuesday January 31, 2023 @08:09PM (#34604910)
How much do you charge to run training sessions on how to write better comments?
Re:Reducing technical debt by valuing comments as much as code by Psyladine on Wednesday February 01, 2023 @09:58AM (#34611326)
Here's a free method that's twice as much work but produces great results:

immediately after composing, for each step and nested step, write a line or two of what its place in the code is for. Write it as though the code is broken and you're following the imaginary line threading through, explained as if to your rubber duck.

Then, having written out the business logic map, look at each written step and see if they're just a description of the logic "iterates through file, passes hits onto nextFunc" and you can safely delete those. They're just glue, really, holding processes together.

What you'll have left is skeletal comments that are restricted to "we did this because this stackoverflow post gave the solution" as well as those mental maps of the solution in your head, which is really what comments are for, future programmers to grok your state of mind and thus better implement their code changes.

Re:Reducing technical debt by valuing comments as much as code by ajross on Tuesday January 31, 2023 @08:52PM (#34605270)
This is misunderstanding the point. Code cannot lie. Reading code (correctly) gives you a correct understanding of the state of the system, no matter how clear or unclear it is.

Reading comments only tells you what the person who wrote the comment believed. It does not tell you anything in particular about how the system behaved, you have to trust the other human beings (in general a long succession of them) to have understood it correctly. And any one of you can mess that up.

Saying good comments have value is fine. But their ability to lie is unique; code doesn't have that misfeature. You can't make comments lie-free by fiat, for the same reason that you can't train your developers not to write bugs.

Given that, IMHO comments have limited value. Don't be a zealot in either direction, but when debugging hard problems, train yourself to ignore the lying comments.

Re:Reducing technical debt by valuing comments as much as code by agalunar on Tuesday January 31, 2023 @09:51PM (#34605704)
This is a good point, and I'm not arguing with it, but I don't think the words "code cannot lie" are the right way to express it.

Code can deceive even if, definitionally, the code states what the computer will do. So code most certainly can lie.

[By analogy, you'd still feel lied to if someone told you something that is technically correct but very misleading: "(Me) It's going to rain tomorrow." → tomorrow comes → "(You) It isn't raining today!" → "(Me) It is raining, in Japan. I didn't say it would rain here."]

I suppose it depends on whether you're considering what the code communicates to the machine or what it communicates to a person.

Re:Reducing technical debt by valuing comments as much as code by galangalalgol on Tuesday January 31, 2023 @10:36PM (#34606021)
How about "code does what it does but comments say what it might have once, and possibly still might do?"

You can have your pipeline regression test code, but not comments. Just recently my mentee found some of my code where I had changed the code but not the comment. I'm a horrible human and wasted his time. If that comment hadn't existed the code might have taken a moment to understand but as it was, he wasn't sure which was the intent.

Re:Reducing technical debt by valuing comments as much as code by _AzMoo on Wednesday February 01, 2023 @12:22AM (#34606755)
While code gives you a correct understanding of the state of the system, it doesn't give you any understanding of why the system is in that state. That's the point from the OP. Code tells you what a system is doing, not why it was designed to be that way. Comments that try and explain what a system is doing can absolutely be wrong and therefore problematic, but there's no way for code to convey the context in which it was implemented a particular way, which is what comments are for.

Code without comments only gives half the story. It gives you the what, not the why.

Re:Reducing technical debt by valuing comments as much as code by baby on Wednesday February 01, 2023 @02:15AM (#34607462)
> Code cannot lie

Sure, but it can take you on a freaking trip. Comment your code bro.

This whole argument makes me think of C coders who say C is perfectly safe as long as you don’t write bugs.

Re:Reducing technical debt by valuing comments as much as code by ajross on Wednesday February 01, 2023 @11:31AM (#34612934)
The point is not to fetishize comments. Write a comment if you feel something needs explanation, but don't freak out about "uncommented code" as a smell or whatever, when reading the code should have been your first step anyway.

And to repeat: when debugging, train yourself to ignore the comments. They will absolutely lie to you.

Re:Reducing technical debt by valuing comments as much as code by baby on Wednesday February 01, 2023 @12:03PM (#34613546)
Imo comments are like formatting. If you don’t enforce it in CI it’s going to be bad
Re:Reducing technical debt by valuing comments as much as code by ajross on Wednesday February 01, 2023 @04:26PM (#34618037)
Forcing developers to write comments[1] just to get code merged seems like the best possible way to ensure those comments are lies.

[1] Which, it's important to point out since you used the term "CI", are fundamentally untestable. There's absolutely no way to ensure a comment is correct. A CI smoke test at the very least verifies code builds and doesn't break pre-existing cases. No such validation is even theoretically possible for comments.

Re:Reducing technical debt by valuing comments as much as code by baby on Thursday February 02, 2023 @01:08AM (#34622757)
I’ve seen it done before and no, it was beautiful, everything was commented
Re:Reducing technical debt by valuing comments as much as code by ac50hz on Wednesday February 01, 2023 @02:31AM (#34607565)
+10

It sounds like we have had similar experiences and have come to similar conclusions.

Learning to code, learning to comment and learning to log are all ways to learn to communicate and represent a means to risk-reduction and importantly, to cost-reduction.