[swift-evolution] [Pitch] Reimagining guard case/if case

Jeremy Pereira jeremy.j.pereira at googlemail.com
Fri Oct 28 04:00:24 CDT 2016


> On 25 Oct 2016, at 13:15, Haravikk <swift-evolution at haravikk.me> wrote:
> 
> 
> I'm inclined to disagree; the keyword wouldn't be much different from the use of the is keyword to test a type (I even suggested using it since it's shorter than matches and wouldn't require a new term), both are run-time operations except where they can be optimised away so there is some precedent for this.

That’s more an argument for changing the syntax of `is` and `as`, perhaps giving them a function like syntax like `type(of:)` not an argument for introducing more operators that break the rules. It’s all very well following precedent, but when precedent is wrong, let’s not.

> 
> Lastly, on it being more readable the issue isn't general readability but rather discoverability. If you see "if x matches .some(let y)" or "if x is let y?" then there's some immediate context for what's going on the first time you see it. An =~ or ~= operator is less clear as it looks like a weird assignment operator (like +=), doesn't mean the same thing as the tilde operator on its own; the only clue to it being a comparison is that it's used in an if condition.

I’m not sure I like compromising readability just so that people who have no Swift experience can understand things a bit more easily.

> 
> I dunno, although I've started using the pattern matching operator, I just don't like it.

It’s a bit similar to Perl’s string pattern matching operator (=~), so to me it seems fine and it’s already part of the language. 


More information about the swift-evolution mailing list