Thoughts on binary vs trinary logic


Last night a friend of mine and I had a conversation about a pattern in computer programming. The language we use most often you can take a variable and assign it to be true or false. A variable is a sort of container for information, and often you place the answer to questions in them.

Suppose that I want to answer the question, "Is Frank right handed or left handed?" Suppose further that Frank filled out a form where he answers if he is right handed or left handed, and I have access to this information, along with many other people who answered if they were right handed or left handed.

One way of storing this information would be to have a variable is_right_handed. If Frank answered 'Right', than this is true and will be set to 1. If Frank did not answer 'Right', then this is false and will be set to 0. The logic of handedness has been settled, and it's stored.

Some time later one might go to use this information and the question needs to be answered again. Instead of from Frank himself, it's answered by the variable we stored the information in. Perhaps a report is printed out, and in that report everyone is listed with their handedness.

One form the report might be generated in would be to answer the question this way, if is_right_handed is equal to 1: then say "Right", otherwise: say "Left". The report is created.

Frank is marked as Left handed, although Frank answered the question by saying, "I lost my hands in a boating accident." He didn't say, "Right" and the program was written with the logic that one must be right handed or left handed, and such a test is "Are you right handed?" Answering no, Frank must then be left handed.

This is a form of logic I notice sometimes. That something must be true or false, yes or no. A judgement must be passed, a side must be choosen, two roads diverged.

In this computer language there is another option, undef. When you get this third value, it often means there is an error in the logic used. That there is nothing to judge, that neither side must be choosen, and that neither road needs be taken to get to where you want to go.