[swift-evolution] ternary operator ?: suggestion

Conrad Kutsch kutschenator at googlemail.com
Sat Dec 19 04:43:07 CST 2015


Hey, I really like the new proposal, gets a +1from me! Especially the case part makes it good to use. I would just leave out the Integer part because it can be confusing and misleading. Do you start counting at 1? Or at 0? MinInt? It’s just super error-prone if you don’t write the number before it.

?(charNum : 0: "A", 1: "B”, ...
might be OK as it would get rid of the many case statements but then again, is this only working for Int or also for float?



> On 19 Dec 2015, at 01:56, Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Thanks for your support! 
> 
> I think parenthesis are preferred because braces are for bracketing lists of statements. Statements may or may not return values. 
> 
> Having the conditional on the inside of the parens helps to show the begging of the demux operator rather than a floating conditional which is a common complaint with the ternary operator. 
> 
>> On Dec 18, 2015, at 3:46 PM, Charles Constant <charles at charlesism.com> wrote:
>> 
>> +1 
>> 
>> I'd be very happy with your new proposal too. I still prefer sticking the value we're using as a key outside of the parens, but it's a minor quibble. Also I can't figure out if parens or curly braces are more appropriate. Does it make more sense for the expression to look like a tuple or a closure? I'm not sure.
>> 
>> Anyhow, I'm good with your new proposal.
>> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/e9aab7e1/attachment-0001.html>


More information about the swift-evolution mailing list