Let’s be honest, no good ever came out of a
However, it’s common for
boolean to prove not quite good enough to represent what’s going on. This is where you’re dealing with a false dichotomy in something.
I’m reminded of a potentially apocryphal story about a UK politician:
Him: the problem is that half of them are crooks
Speaker: please withdraw that comment
Him: ok, half of them aren’t crooks!
We hit a similar thing in some test code recently. We want to detect whether the images have loaded on a front end screen. We have the front-end detect any failures in loading images and attaching an HTML
class to images that failed to load. We were trying to detect the absence of those classes as proof that the images had loaded.
This led to a situation where if any failed to load, the test was failing, which might be a reasonable failure. In our case, however, the existence of any working image would be enough to pass the test. So we decided to add a class to the image element that said when it was loaded. We detected this from the state of no-loading-error.
This, however, led to a new problem. When the image hasn’t even started loading yet, it can’t be said to have a loading error. So how do we avoid prematurely declaring the image as loaded?
It turns out that this is potentially a tri-state. The image can be said to be
In our case, it might be simpler to represent this with two
boolean variables, rather than one. This allows us to more simply express whether to tag it with each of the
loading failed or
loading succeeded classes.
This does allow 4 states, but that’s not necessarily a bad thing.