All koans

Does the empty match?

Two boxes are empty. Are they the same?

Find friends whose city
Friends, and the database's answer for each
NameCityMatches?
AviChicagoYes
BeaAustinNo
ChenemptyMu
DanaChicagoYes
EliemptyMu
FemiSeattleNo

Found 2 of 6: Avi, Dana

2 answered Mu and quietly vanished. Asking the opposite finds 2. Together that's 4 of 6.

Ask for friends who live in Chicago, then for friends who don't. Count everyone you found. Then try the other questions.

See the answer Hide the answer

The answer

NULL, the unknown value

Chicago plus not-Chicago should be everyone. It isn’t: two friends were in neither list. They’re the ones whose city was never filled in. A database doesn’t treat an empty cell as “nothing”. It treats it as unknown, and calls it NULL. Is an unknown city equal to Chicago? It can’t say. Is it not Chicago? It can’t say that either. So the honest answer is neither yes nor no, and a search only returns rows where the answer is yes. The rest disappear without a word.

Even two empty cells aren’t equal: one unknown is not known to match another unknown.

That’s the monk’s mistake too. He asks a yes-or-no question, and Joshu answers “Mu”: not yes, not no, but the question doesn’t fit. Engineers learn to ask a different question: “is this cell empty?” (IS NULL). Try it in the toy: the missing people come back.

Some questions have no yes or no answer. Good code plans for that.