Article
George Boole Returned As a Zombie and is Gnawing on My Brain
This is about that oft-neglected corner of programming, the humble boolean. Perhaps, by thinking about what’s going on in many boolean expressions, we can iron out his quickly-forking complexity. And, oh, what luck! Here’s a slab of boolean logic that I just happened to have at hand (variable names have been changed to protect the innocent):
I have found that stuff like this is easy for me to get wrong, hard to read, and hard to refactor. What could be done to simplifiy these cases? Consider just the first line of the above, (hash[:foo] == "1" || !hash.has_key?(:foo)). Already, there are two competing interests here. What is going on is that we are conflating value-testing with existence-testing. What we may ...