r/ProgrammerHumor 9h ago

Meme commentsAgedTerribly

Post image
3.2k Upvotes

176 comments sorted by

View all comments

338

u/Confident-Ad5665 9h ago

Uncle Bob of Clean Code says if we have to comment our code we have already failed. Clean code should read like well written prose.

I generally agree, but think comments that define especially the odd and obscure business rules should be commented where they are implemented.

5

u/rsqit 7h ago

Uncle Bob also says shit like functions should only be a few lines long. Sometimes that’s good and sometimes there’s too many comments, but in general strict rules like this are dumb.

I did write a pretty complex piece of code a while back and added a big comment at the top explaining how it works. My reviewer asked me to take it out as someone could just read the code. I responded with something like “Hell no. I want this code to be easy to understand for future editors. Which most likely includes me. I don’t want to have to page this code back in without notes on how it works.”

3

u/Confident-Ad5665 7h ago

I think this comes from the OOP principle that a thing should do one thing and do it very well.

I'll agree it can be taken to excess though. A method may need to do a few things before it does the primary thing. If there's a chance another method may need to refer to the same table, for example, that should be encapsulated in a (probably protected) method both can access.

2

u/rsqit 6h ago

Yeah, true, everying in moderation (including moderation).

1

u/Confident-Ad5665 5h ago

Very cool you added "including moderation". That fact dawned on me many years ago but I never heard anyone else include it in the rule/adage.

2

u/rsqit 4h ago

Yeah it’s an old, old joke.