Hacker News new | ask | show | jobs
by cjfd 2073 days ago
And then one puts in one too many in a case where fall through actually was the idea....
1 comments

I try to be explicit and place a comment saying fall through if it is the intended behavior. This helps to inform the next person reading the code.
So there was a classic bug in the game NetHack where there was indeed a comment indicating there should be a fall through. Then somebody added a new case, and the fall through now went to the wrong place. But since the comment said it was supposed to fall through, nobody reported the bug.

https://nethackwiki.com/wiki/Yeenoghu#.22A_ludicrous_bug.22

There are linters that raise an error when there is a fallthrough without an explicit comment [0]. I feel like that should be a must for working with C code.

[0] I don't remember which one it actually was. Possibly something commercial for MISRA compliance.

Actually in C++ there is a fallthrough attribute in the language nowadays. https://en.cppreference.com/w/cpp/language/attributes/fallth...