Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Also, for example if you are implementing chess then you should have an enum of Black and White rather than using `bool white`.



Black 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)


Why?

If there are only two states, and provably will never be more; it's either or.


Because 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 ...


Yes, and I agree in most cases. But the previous example is not one of those.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: