[swift-evolution] ternary operator ?: suggestion
possen at gmail.com
Tue Dec 22 11:47:08 CST 2015
These are some very interesting ideas to explore. I definitely want to play with the bar character as a separator. This could nicely deal with the problem of the double colon in the hybrid approach.
I like this thinking as it really explores a different approach.It is cool the way it can be lined up like that and it reads well when you think of the bar as “when”. I am a little concerned that some may be considered weird but not better than the ternary, which is some of the feedback I got from my earlier designs. I suppose if we are making a breaking change though, that may be okay but keep in mind it there should be a reason for making it different. This suggestion definitely has a different feel than the existing ternary. How do people feel about that?
I also agree, I am not sure how that would work for expressions.
> On Dec 22, 2015, at 7:36 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
> This looks reasonable in declarations but how would it work in expressions? Or are you suggesting that it is only usable for declarations?
> Sent from my iPad
> On Dec 22, 2015, at 9:25 AM, Angelo Villegas via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> I for one feels like the ternary operator still has a future with Swift.
>> If the discussion with ternary will go on though, I would like to weigh in a suggestion:
>> let a | x == y = a
>> | otherwise = b
>> let b | colour.Red = 0xff0000
>> | colour.Green = 0x00ff00
>> | colour.Blue = 0x0000ff
>> | otherwise = 0x000000
>> My rule of thumb for a style like this is that if you can read it as if it was English (read | (bar) as "when", | otherwise (bar otherwise) as "otherwise" and = as "is" or "be"), you're probably doing something right.
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution