Peter Bissmire

Communications & Language Services

Technical and general translations, French/German -> English

18-08-08

Boolean condition

Most programming languages require that, in conditional statements, if be followed by something enclosed in brackets. This is fine when something is an expression, which is frequently the case. Something must be evaluated to a boolean value (true exor false) and we need the brackets to define where something begins and ends.
Example:
if (today == Christmas){celebrate;}

Given that if must be followed by something that evaluates to a boolean value, the brackets become redundant when if is followed by the identifier of a variable that has a boolean value or a function that returns a boolean value. Few programming languages, however, allow the brackets to be omitted.
Examples:
if itsChristmas {celebrate;}
or
now = Christmas;
if defined(now) {celebrate;}

Not only does this save a little bit of typing, it also makes the code more naturally readable and it is hard to see how this creates difficulty for the language interpreter/compiler. Some languages also permit the braces to be omitted where there is only one statement in the block governed by the condition - even better in terms of being like natural language.

Language designers please note!