[swift-evolution] [External] Re: [Pitch] Replace the ternary operator with an in-language function

Chris Lattner clattner at apple.com
Wed Oct 26 23:40:17 CDT 2016


On Oct 26, 2016, at 11:54 AM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Bottom line, most developers know the ternary expression if they come from C, C++, Obj-C, Java, C# (The list goes on). Why does Swift need to be different for style reasons. We will be making a niche language, because what you learn isn’t portable to another language like it is if you learn Java, then get a job programming in C#.
> 
> While I agree on most of this, I think there is reasonable justification to discuss this on the basis of it using the question-mark; Swift uses the question mark extensively for handling of optionals, so there is an element of confusion present there, it also uses the colon in a somewhat unfamiliar way as well, so it's a twofold oddity in Swift.
> 
> That said, I'm not sure replacing it with a function is superior; this is something you can do yourself easily enough if you feel you need to, and which learners can likewise do if they don't know about, or don't like the operator.
> 
> So the question really is whether there's an alternative that is similarly concise, and on that I'm not so sure, so I'd lean towards leaving it as it is, but advising people to be careful about where they use it, as its very advantage in size can be a disadvantage in readability, so it should be used with care at all times.

I’ll add a couple of more points:

1. This was extensively discussed in the Swift 3 release cycle, in multiple threads, and never went anywhere.
2. Changing this in Swift 4 is extremely unlikely even if there is a good answer, because - unlike in Swift 3 timeframe - any change that breaks source code needs extreme justification of why it is the right long term thing to do.  I can’t fathom a rationale for this in the case of the ?: operator.  Merely being potentially confusing is not enough.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161026/6d2207b9/attachment.html>


More information about the swift-evolution mailing list