Why using Boolean to represent ternary states is a bad idea
The intention of my previous entry is not to advocate the usage of Boolean to represent ternary state but to document a usage I found while reading some open source code.
Use NULL to represent state is technically valid and common practice. Nullable column is often used in database design and many APIs return NULL.
However, people seem to really hate this idea. Why?
I believe the reason is that the usage violates the "least surprise" principle. As programmers, we are hardwired to think of boolean as binary state. The usage in this case, although valid, is against human psychology.
Comments
However, I think some shy away from this because deciphering between a forgotten, and a specifically NULLed field can be an issue.
Basically the problem turned into an argument, because nulls happen when not wanted too.
Java tiger and autoboxing may add a new dimension to this.