Wednesday, April 28, 2010

Programming Language Nitpick

Many computer languages sport built-in keywords for logical truth values: .TRUE. and .FALSE. or true and false or whatnot. In every such language I'm aware of, these are used in comparisons: you have a logical expression and you are comparing it to the value TRUE.

The problem is that the English words "true" and "false" are adjectives, not nouns: the semantics of a comparison are that you are taking one thing and comparing it to another thing, but "true" isn't a thing, it's a description of a thing. (This is why an expression like "if (true == a)" looks backwards, despite being perfectly legal.)

Boolean keywords should be named "truth" and "falsehood" to more accurately convey their usage.


Anonymous said...

Does "if (truth == a)" or "if (a == truth)" really look any better?

I think the real problem here is the equivalency indicator. a does not *equal* true, it just has the *property of being* true. Or it is a *subset of* the truth.

So we could have true(a) and false(a). Or maybe a.truthValue. Or memberOf(truth, a).

tps12 said...

Yeah, I was just trying to fix comparisons to be grammatically correct in English terms, but actually allowing you to use adjectives would be a cool language feature.

C# has an "is" operator used for recognizing types ("if (obj is IStream)") which could serve as a model from a syntax standpoint.