[swift-evolution] ternary operator ?: suggestion
sean at fifthace.com
Thu Dec 3 23:08:11 CST 2015
I agree that using ? for ternary feels.. uncomfortable in Swift. I wouldn't mind seeing Python-style or just eliminating it entirely in favor of simplicity.
> On Dec 3, 2015, at 10:48 PM, Dan Appel <dan.appel00 at gmail.com> wrote:
> I agree that ternary can make code unreadable, especially so with the ‘?’. I personally like the Haskel option the most, but it introduces a new keyword ‘then’, which isn’t great either. Python’s "y if x else z" is therefore, in my opinion, the best alternative.
> Also, I found it interesting how split the Rust community was about removing the ternary operator.
> Dan Appel
>> On Thu, Dec 3, 2015 at 7:58 PM J. Cheyo Jimenez <cheyo at masters3d.com> wrote:
>> Would you consider replacing the C style ?: ternary operator to something that does not use the question mark and colon ?
>> The use of "?" can be confusing when speed reading code with optionals.
>> Consider this code as somebody learning swift as their first language.
>> let result = !condition ? 1 : 2
>> Some alternatives:
>> if predicate then expr1 else expr2
>> result = x if a > b else y
>> The advantage of not using the question mark is that the language will be more consistency on the use of "?" to mean only optionals.
>> swift-evolution mailing list
>> swift-evolution at swift.org
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution