Re:Flags Are a Code Smell (2014)
by astrobe_ on Sunday May 22, 2022 @04:33AM
(#31466090)
Flags are misused if their meaning is entangled, e.g. flag A is meaningless when flag B is set. In this case, you don't need flags but states, as TFA points out (with far too many words, IMO); in C lingo, when this happens you should switch from booleans to enumerations - because programmers worth their salt won't have entangled flags in something designed from scratch, it is more something that can happen when you add features.
[ Parent
| on HN ]
Re:Flags Are a Code Smell (2014)
by adhesive_wombat on Sunday May 22, 2022 @04:55AM
(#31466185)
They also crop up all the time in embedded code, because flags are how lots of hardware works.
But, yes, it's usually a different smell in that context because you just know someone is hot-gluing the exact bitmask for a thing into some hardware-agnostic controller code without writing a proper interface that translates from an internal representation (say, an enum) to actual physical bits.