3 ms·
Also, for example if you are implementing chess then you should have an enum of Black and White rather than using `bool white`.
by frou_dh 3y ago
Also, for example if you are implementing chess then you should have an enum of Black and White rather than using `bool white`.
- WalterBright 3y agoBlack and White are two states where you should never use negation, and hence bool is not the right choice for self-evident code. I.e., you should never see this in code: if (piece != Black)
- codr7 3y agoWhy? If there are only two states, and provably will never be more; it's either or.
- WalterBright 3y agoBecause negation is a cognitive problem people have. The other problem happens when a third state is added - it becomes very hard to find all the dependencies that need updating. A classic case of this: if (!Windows) ... do something for Posix ...
- codr7 3y agoYes, and I agree in most cases. But the previous example is not one of those.