Oh God… not again! We already have had hundreds of email about this on the list.
Indeed. This is how a technical non-problem turns into a political dispute.
The proposed IfThen() aka iif() aka iff() aka IfThenElse() intrinsic is supposed to act differently, than existing Math.IfThen. The key difference, is that only one of the expressions is evaluated, based on the value of condition. If condition is true, only "then" expression is evaluated (and returned), if condition is false, only "else" expression is evaluated.
But here comes the problem:
The intrinsic looks like a function, but acts differently. In case of a function all arguments are evaluated prior to the function call. That might cause confusion, even though there're already intrinsic that're acting in a similar manner, i.e. assert().
Logically, it's better to have as less exceptions as possible, that's why it is desirable not to add another exception into RTL.
So, in the thread another proposal came up - let's have if..then as an expression. That would make if..then an operator. With implementing this, a code like
x:=if a then b else c;
would be possible. It
might look nice, but ...
whenever a new operator is introduced, it must have a defined precedence. For example, what the value of x would be:
x:=if true then 5 else 3 + 4;
should it be resolved as:
x:=(if true then 5 else 3) + 4;
or
x:=(if true then 5 else (3 + 4));
If using intrinsic, is really not a problem, since function call (which it looks like) takes the higher precedence:
x:=IfThen(true, 5, 3)+4;
So defining the right precedence is critical to usability of an operator, since it might be a source for potential bugs.
But adding a new operator with its precedence opens a big can worm.
First of all, it breaks Pascal fundamental simplicity.
Pascal has only
4 (or 5 levels) of precedence.
Compare it to C with 18 or even Algol with 12 levels.
More levels, the harder expressions are to be understood and read.
Secondly, it also creates precedent of extending the language with a new operator, so more operators could be added (case-expression... and so on). More operators -> greater complexity.
Thirdly, potentially one might start asking about overloading these new operators, bringing even more complexity.
Another point was made, that neither Ifthen() intrinsic nor if-expression solves any technical problems.
What they do could be achieved by using if-statement. So they're nothing more but a syntax sugar (
not very welcomed, in general, that is intended to make the development a little bit easier (less typing, easier to port C-like language code)
There's a saying:
the road to hell is paved with good intentions. Is this case the sample of the saying?
What makes it all hard (over 200 emails of the mailing list), is that the patch has already been provided, it's very easy to accept it technically.
The optimal solution might be - not to do anything. Put the patch on hold, until the language is ready for it or until Delphi implements it also. (I wonder if Delphi developers had the same problem and decided not to add it to the language)
thanks for reading, btw!