Re: Opinions about conditional built-in names?
Woonsan Ko <[email protected]> Mon, 01 Jun 2015 15:41:49 -0400
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <[email protected]> |
On 6/1/15 3:26 PM, Daniel Dekany wrote: > 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... :) Oh you're right. Long time passed after I wrote XSL files last. :-D > >> '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"). Yeah, "then" sounds better to me than anything else. > >> 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". Agreed. Not sound fluent. Kind regards, Woonsan > >> 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. >>> >> >> > -- [email protected] www.onehippo.com Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111 Amsterdam - Oosteinde 11, 1017 WT Amsterdam US +1 877 414 4776 (toll free) Europe +31(0)20 522 4466 ------------------------------------------------------------------------------