[swift-evolution] ternary operator ?: suggestion

Craig Cruden ccruden at novafore.com
Thu Jan 7 06:56:45 CST 2016

Enums in Swift seem to serve two purposes.  

1. Enums as just a simple enumeration of a small set of values (spades, hearts, diamond, clubs)  (same as something like java enums)

2. As Algebraic Data Types (which could easily have data/arguments). 

The second case is where the lack of a filter clause would be problematic in regards to pattern matching / expression.


I did not take offense to it - Swift is a language I might use more often (if it became useful on the server-side) but I don’t use regularly other than quick UI mockups - as such ugly code is easy to create.  (I don’t generally work on the UI since my perfectionist/OCD side comes out and I get sucked down the rabbit hole).    Was not worrying about simplification or reducing functions to a few lines of code - since it was not the focus.

> On 2016-01-07, at 18:23:43, Charles Constant <charles at charlesism.com> wrote:
> My previous message was probably rash. I should have thought it over instead of writing a knee-jerk response.
> I'm not sure now that it's the syntax that is the issue in that example. After I sent that message I started thinking about what I would do in real life if I had to write that code, and there's plenty of ways one could simplify it. For example, one could write a couple closures to handle the different types of calculations that are done with the result, etc. 
> My gripes with the code are probably more to do with the explicit casting, and - as you point out, Craig - the "let" for the argument of that enum case. The casting could be worked around, easily. And most enums don't even have any arguments...
> Just ignore my last message. I think I was off base.

More information about the swift-evolution mailing list