[fpc-devel] new features and facilities

Michael Van Canneyt michael at freepascal.org
Fri Oct 9 00:37:02 CEST 2015



On Thu, 8 Oct 2015, Mark Morgan Lloyd wrote:

> Michael Van Canneyt wrote:
>> On Thu, 8 Oct 2015, Sven Barth wrote:
>> 
>>> Am 08.10.2015 19:10 schrieb "Ralf Quint" <freedos.la at gmail.com>:
>>>> 
>>>> On 10/8/2015 9:54 AM, Sven Barth wrote:
>>>>> 
>>>>> 
>>>>> I had the idea to implement inline-if as well. I think the syntax I
>>> selected is derived from Oxygene, but it looks very Pascal and shouldn't
>>> break anything:
>>>>> 
>>>>> left := if expr1 then expr2 else expr3;
>>>>> 
>>>>> Thereby expr1 returns Boolean and expr2 determines the type of the whole
>>> inline-if, thus expr3 needs to be compatible to expr2.
>>>>> 
>>>>> 
>>>> Sorry, but that doesn't "look Pascal" at all, and is anything but easily
>>> understandable, specially given the possible complexity of expr[1,2,3]...
>>> 
>>> And you think C's ternary would be more Pascal? Also you need /some/
>>> definition of what defines the type no whether what syntax you choose (in
>>> addition expr1 is the same as in normal ifs, so it's only the "complexity"
>>> of expr2 and expr3). And no, "the left side" is not the Pascal answer
>>> either.
>> 
>> Actually, yes I think C's or Javascript's ternary is better suited.
>> 
>> Let me explain. If I see
>> 
>> If expr1 then expr2 else expr3
>> 
>> it says 'statement' to me. But
>> 
>> a ? b : c;
>> 
>> Says "expression" to me.
>> 
>> So
>> 
>> left := a ? b : c;
>
> OK. So presumably, since false < true, b is executed if a is false and c is 
> executed if it's true? >:-)

Why would anyone in the world think that ?

Many pascal programmers do not even know that false<true and ord(false)=0 and ord(true)=1,
or even that a boolean is equivalent to an enumerated.

The number of times I've encountered

if expr = true then

is staggering, and tends to make me very depressed...

By contrast, many people these days have encountered some C-ish language and 
do know ternary expressions.

>
> After all, while concise C-style operators work well in expressions this is 
> not a simple expression where all components are evaluated:

Of course it is the same. Boolean expressions by default are shortcut-evaluated. 
So the ternary is completely equivalent to that and should not present any difficulties whatsoever.

Michael.



More information about the fpc-devel mailing list