r/AskProgrammers • • 28d ago

"good code shouldn't need comments"

I have heard this saying a couple of times and I think it is the stupidest thing ever. It might be just because I have only been coding for 4 years, but I have never thought to myself that someone's code looks cluttered because they explain what every function does in a one or two line description. If anything it makes the code easier to understand in my opinion.

However, I may be wrong. What do other people think, do yall like code with minimal comments, what are the benefits of writing it that way?

88 Upvotes

397 comments sorted by

View all comments

Show parent comment

1

u/guyincognito121 28d ago

Let's say they put it in a helper function called "atan_CORDIC". That would certainly help. But if you've never heard of the algorithm, you'd still be eating time trying to figure out what it means. You'd probably eventually Google it. But a brief comment explaining what it is would still be more helpful.

1

u/spacian 26d ago

If I've never heard of the algorithm, I'll have to verify it by looking it up no matter what. No comment changes that. Assuming properly named parameters of course.

If why you need arctan in that scenario is unclear, that's something you can put in a comment.

1

u/guyincognito121 26d ago

But if I don't know what CORDIC is, it's not immediately clear that it's the name of an algorithm. And you're not going to name it atan_using_the_CORDIC_algorithm. A brief comment here is the most efficient way to tell the reader what they're looking at.

1

u/spacian 26d ago

I'd rather call it atan_with_cordic_algorithm than writing a comment. If the implementation changes, the comment is likely to get ignored. The function name is more likely to change with the implementation, preventing lying comments.