What do you mean with "point error generation"?
I said "to the point error generation". If you have an in-expression if, the whole errorhandling situation changes. The IF might suddenly associate with the next begin end block etc.
In case of the
if-expression that would not be the case, because an expression is either separated from the next one by a semicolon or is followed by an
end, thus there would be no possibility to associate it with a
begin. Also that expression could not contain
begin…end-blocks as those are not expressions.
What is indeed problematic (but that's a general problem of the ternary operators) is how "greedy" it is (especially the
else-branch):
a := if y > 4 then y else z + 4;
// can be evaluated either as
if y > 4 then
a := y
else
a := z + 4;
// or
if y > 4 then
a := y
else
a := z;
a := a + 4;
What the
if-expression solves better than the ternary operator is the "reach" of the tested expression. In C(++) I always struggle with this:
Does this test
y > 4 or
z + y > 4? In the end I stuff that into brackets to avoid any misconceptions:
a = z + (y > 4) ? y : z;
// or even
a = z + (y > 4 ? y : z);
Using the
if-keyword this potential ambiguity (potential, because the compiler follows a clear rule there; one just has to remember it) is avoided.