logoalt Hacker News

JohnFenyesterday at 5:24 PM3 repliesview on HN

> A comment "this CANNOT happen" has no value on itself.

I think it does have some value: it makes clear an assumption the programmer made. I always appreciate it when I encounter comments that clarify assumptions made.


Replies

addaonyesterday at 5:32 PM

But if you spell that `assert(false)` instead of as a comment, the intent is equally clear, but the behavior when you're wrong is well-defined.

show 4 replies
dllthomasyesterday at 8:06 PM

Importantly, specifying reasoning can have communicative value while falling very far short of formal verification. Personally, I also try to include a cross reference to the things that could allow "this" to happen were they to change.

skydhashyesterday at 5:31 PM

Such comments rot so rapidly that they're an antipattern. Such assumptions are dangerous and I would point it out in a PR.

show 1 reply