[swift-evolution] ternary operator ?: suggestion
possen at gmail.com
Thu Jan 7 02:36:05 CST 2016
Big +1 on that, I really like the confidence that people won’t easily stick side-effect code in the middle of the big inviting case: sections of the switch statement. That is a safety feature. This really supports a functional programming mindset which Swift is already popular for.
To this I add:
• Knowing that every case will return a result of the same type and returns a value.
• automatic type inference
• more concise code, and reduction of repeated code to assign the results.
• less likely people will use var when let is correct, currently the compiler will warn but this avoids any confusion from the start.
• fall through, break and continue are not a concern because you can only put expressions there.
> On Jan 7, 2016, at 12:07 AM, Charles Constant <charles at charlesism.com> wrote:
> > would this feature pay for itself?
> If I were coding in a big team, I'd think the fact alone that neither I nor anyone else in the company, can come along and polute my assignment with unrelated code is a plus.
> As it stands, every "switch" statement requires the person reading to review the whole thing. With the current proposal, it's not going to compile unless the statement only contains an assignment.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution