Re: Opinions about conditional built-in names?

Daniel Dekany <[email protected]> Mon, 1 Jun 2015 21:26:53 +0200
Newsgroups gmane.comp.web.freemarker.devel
Message-ID <[email protected]>
Sunday, May 31, 2015, 7:50:20 PM, Woonsan Ko wrote:

> I personally prefer having the default value option inside the
> parenthesis, without having to depend on the default value after '!'.
> So, I like the idea the odd number of parameters for a default value.
>
> Regarding the original question about 'switch' and 'choose', I like the
> 'switch' very much, but I'm not sure if 'choose' is a good name for
> ternary operator. In XSL, 'choose' means just one choice of the
> 'switch'.

Actually, in XSLT "choose" stands for "switch" (and "when" stands for
"case"). But that just proves how confusing this word is... :)

> 'choose' sounds like related to one of the 'multiple' choices
> to me.

Well, I'm also unhappy with "choose", I just couldn't find better
yet... What do you think about "then". Apart from the lack of "else"
in it, it reads quite fluently: loggedIn?then(user.name, "unknown").

> Another option to consider might be 'iif' [1], which seems a bit clearer
> to me than 'either' and others.
>
>     someBoolean?iif(whenTrue, whenFalse)
>
> Just my two cents,

I have played that idea back then, but I'm afraid very few knows what
does "iif" stands for. Also loggedIn?iif(user.name, "unknown") can be
easily misread like: we are logged in IF user.name is "unknown".

> Woonsan
>
> [1] http://en.wikipedia.org/wiki/IIf
>
> On 5/30/15 6:02 AM, Daniel Dekany wrote:
>> And regarding the semantics of ?switch... as it sands now, if there's
>> no matching choice, that will be an exception that says:
>> 
>>   The value before ?switch(case1, value1, case2, value2, ...) didn't
>>   match any of the case parameters, and there was no default value
>>   parameter (an additional last parameter) either.
>> 
>> So, if you have an odd number of parameters, then the last one is like
>> the default branch of switch in Java.
>> 
>> I have also considered just returning null if there's no match, and
>> then one can write ?switch(...)!theDefault, but then if someone
>> doesn't give a default, the error messages will just say that
>> ?switch(...) has evaluated to null/missing, which many users won't
>> understand why's happening. Also it has the same problems as
>> ?then(this)!that had.
>> 
>
>

-- 
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------