by hyperpape · 5y ago · 0 comments
Would you find the comments in the second version helpful, or should they also be removed?
Edit: let me lay my cards on the table. If the comments really are necessary, it doesn’t seem elegant. I’m pro-comments, but that’s because not all code can be readable and elegant all the time.
So I'll disagree with the notion that only illegible or unreadable code needs comment.
I've been C/C++ for about 25 years.
So at a function level the comments is giving a highlevel description to the reader as to the functionality contained, and at the line level comments exist only to say describe the programmers intentionality, why it was implemented this way rather than some other way.
I have generally found (there are always exceptions) that if you find yourself needing "what" comments within a function you should be considering breaking it into smaller pieces.
I've been being paid to write c/c++ for about 25 years
The particulars matter.
// indirect is either &head or &(node->next), so *indirect is equivalent to "next node"
Someone who knows their C should be able to figure it out in a few minutes by just reading the code.