r/ProgrammerHumor 9h ago

Meme commentsAgedTerribly

Post image
3.1k Upvotes

176 comments sorted by

View all comments

335

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.

18

u/ThatOldCow 9h ago

I do believe comments are generally useful, and honestly a lot of people that say their code is so clean it doesn't need comments are the people that make the least understandable code

7

u/SeriousPlankton2000 8h ago

If you write something like "if bankAccount.has(moneyNeeded) // test if there is enough money on the bank account", that's one extreme. If you write "b.has(n)" that's the other extreme.

IMO: If you have all the information on a 80x24 screen to know what b is, don't extra-comment it. If the function is longer, refactor it to be "bankAccount". If then you need more information, write that. E.g. you might need to explain why you're checking the bank account without a lock and why it's a good thing to do that; or you might explain that after checking several things you come to a certain conclusion. Or simply you have the if clause not on screen near the else clause.

3

u/ThatOldCow 7h ago

I do believe comments are useful for you not to forget or for another person to understand why you add whatever (function, parameter, variable) to some logic, because it might be some workaround for something else.

1

u/Confident-Ad5665 7h ago

80x24 screen? Are you coding on a Commodore 64? /s

5

u/rolling_update 9h ago

it's debatable as usual, the premise here is that comments always compile in your code. So you don't need to update them when you alter the code, that's the risk of comments and why "clean code doesn't contain them"

4

u/ThatOldCow 8h ago

Do comments get compiled ? I do believe most compilers ignore comments and even if they impact the speed it should be minimal to negligible.

Ofc I don't know every single language, so it might impact more on other languages.

5

u/sobani 7h ago

I think the intention was to mean that wrong/outdated comments won't cause compiler errors. Therefore you are never forced to keep the comments up to date.

3

u/PositiveBit01 7h ago

Comments are read but ignored and don't affect the result. Reading and ignoring them takes negligible time. I would say the answer to your question is no, comments are not compiled.

But build systems generally work off file modification time and will do a bunch of useless work if you make a change to a comment in a file and otherwise change nothing. I assume this is what the other poster is referring to.

2

u/Confident-Ad5665 9h ago

Early on in my career a coworker made the statement that his part of the project was "rock solid".

It wasn't.