[swift-evolution] [Accepted with Revision] SE-0099 Restructuring Condition Clauses
Brent Royal-Gordon
brent at architechies.com
Thu Jun 9 03:47:50 CDT 2016
> Can we get some clarification as to why ‘where’ is being chosen to be retired here? I’m deeply disappointed by that decision as enabling the consistent use of comma as a separator does not preclude the use of where for simple cases that don’t require it. I’m all for having a more usable separator for complex conditionals, but I rarely need it, meanwhile in common, simple conditional bindings and patterns I find the ‘where’ keyword a lot more readable, i.e:
>
> if let value = foo where foo > 5 { … }
I think there may be a case for keeping the `where` keyword—but before, not after, the equals sign.
if case .cartesian(let x, let y) where x != y = point { ... }
if let value where value > 5 = foo { ... }
Why? Consistency with other `case` statements. I recently made the same point about `for` loops: `where` is part of the pattern-matching syntax, and it ought to be attached to the pattern it refines. Letting it float into other parts of the statement unmoors it from its meaning.
That will probably read strangely for some current uses of `where`—specifically, ones that have a condition unconnected to the preceding pattern—but that's when you should use a comma to introduce a separate Boolean condition clause instead. Personally, I think the `if let value` example above would probably be more appropriate as a Boolean condition clause, but tastes differ.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list