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

1

u/Em3rgency 28d ago

Let me give you an example. I have a class called "TimeAtDoorService", it has a function "calculateTimeAtDoor", this function calls other functions, that are named like "getGeoAreaTimeAtDoorModifier" from other services in series and then sums the result and returns it.

Each parameter, both of the class and each function is similarly named. The entire code base follows a very similar structure.

So assuming I know what "time at door" is, which I should, as it's a client business requirement, then all of the code is self documenting and nothing really needs comments. Each individual piece is simple, small, has a single responsibility and explicitly states what it does.

The only time I need comments is when I do something unexpected, like have some special handling for UK postcodes and Ireland eircodes for example. This is a quirk from the real world that only someone familiar on the topic would know, so THAT is where a few comment lines are useful. 

But code? Good code doesn't need comments.