[swift-evolution] ternary operator ?: suggestion

J. Cheyo Jimenez cheyo at masters3d.com
Thu Dec 3 21:58:19 CST 2015


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:

Haskel

if predicate then expr1 else expr2

Python

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.


References:
https://devforums.apple.com/message/1020139#1020139
https://github.com/rust-lang/rust/issues/1698#issuecomment-3705066
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/0c2152f9/attachment.html>


More information about the swift-evolution mailing list