[swift-evolution] Proposal: Pattern Matching Partial Function (#111)

Charles Constant charles at charlesism.com
Fri Jan 29 02:06:47 CST 2016

Sorry for the barrage here, Paul :)

> I’m not even convinced the new syntax is clearer so much as cleverer.

As I've followed the various threads for switch-like assignments, I've been
thinking a lot about how valid it is to say that more explicit is all that
helpful to beginners. I wish I had the resources to test these assumptions
with actual people who had never written Swift.

As an example.

We assume that this:

    let phrase: String

    switch( temperature ) {

        case .Cold: str = "Too cold"

        case .Hot:  str = "Too hot"

        default:    str = "Just right"


is going to be easier for beginners than something like this:

    let phrase = temperature ?

        "Too cold" if .Cold :

        "Too hot” if .Hot :

        "Just right" if _

I'm using a short version here that is not the actual proposal, and that we
won't use (since we don't want to overload "if"). But I have a strong hunch
that a beginner is not going to find the longer version any more clear.
There's a lot of syntax for the programmer to parse in the "switch"
statement, as it stands. I suspect the less redundancy we have, the easier
it is to figure out what is going on.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160129/4b13e10d/attachment.html>

More information about the swift-evolution mailing list