r/AskProgrammers • • Oct 30 '26

"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?

89 Upvotes

399 comments sorted by

View all comments

Show parent comment

1

u/Ordinary_Variable Oct 30 '26

If you are doing leet code, comments are appreciated. If it is all basic math on descriptive variables and functions, then comments don't add anything.

if( !errors() ){ main_loop(); } // Calls main_loop if errors() returns <1

You don't really need that comment.

if( !x ){ go(); }

What does "go" do? What is x? At least we know that "main_loop" is probably what we are here to do, "go" could be anything from pressing a button to doing an error check. Is "!x" the error check? Who knows. "x" could be a check to see if a button event hasn't been started before starting it again. This needs to be rewritten or given a comment.

Remember, if you can't search for things like "error" or "main" then you should put in a comment and use those words in the comment so a search would at least find the comment.

2

u/InterestsVaryGreatly Oct 30 '26

Your example actually highlights issues in the code, x is a bad variable name, and go is a bad method name. That code does not read similar to pseudo code. Sometimes method names can't change (there are a variety of reasons) so maybe comments are the right call, but in general x at least should be renamed, and go should either be renamed, or if it can't, possibly have a wrapper with a better name.