Skip to content

Comment on Documentation is for computers to read (or: Commenting Code is Evil)

Comments

This is a very frequent discussion in my circle of hackers - to comment or not to comment. I'm on the "not to comment" side of things; either your tests or your code should speak for itself, if it's so complex that you need to leave a comment - you're doing it wrong.

I haven't seen this discussion on HN yet - so I wanted to get the opinion of so many people that write code day in and day out and may be responsible for maintaining code they haven't written themselves.

Sorry, but I don't buy the whole "if it's so complex that you need to leave a comment - you're doing it wrong."

Take, as a counter-example, any of Knuth's literate programs. Do you really want to say he's doing it wrong?

Some things are that complex. And sometimes, the best way to make sure that the code is understandable is to add some human-readable text.

It's naive to think that humans and compilers should both be able to parse and comprehend the same text with the same ease.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.