4 ms·
As others have pointed out, that is actually a stunted and quite limited version of pattern matching that existed in other languages for years and even decades
by bmitc 3y ago
As others have pointed out, that is actually a stunted and quite limited version of pattern matching that existed in other languages for years and even decades before Swift.
F#, OCaml, and Standard ML are the primary examples. It's surprising to me how ignored these languages are.
- arwhatever 3y agoLanguages without this feature are basically refusing to wash their hands between the morgue and the maternity ward at this point.
- tialaramex 3y ago[This is a reference to Ignaz Semmelweis, a Hungarian medic who wanted doctors to wash their hands properly based on his observations of the difference between the outcomes for women giving birth who were cared for by midwives (who don't work with corpses) and medical students (who do). This is very slightly before modern germ theory is established, so the doctors who reject Semmelweis' suggestions aren't strictly rejecting known facts about the world - Semmelweis can't explain why it's important to do this, only that it will work (which it does).]
- bmitc 3y agoThanks for explaining the reference! I was wondering about that as I had never heard that turn of phrase before. I looked him up and apparently he was put into an asylum due in part to his recommendations and the rejection of them and subsequently beat to death while committed. An absolutely brutal example of being persecuted for being right.
- wilg 3y agoI don't think Swift's enum with associated values are pattern matching. You can use pattern matching to unpack them though. (https://docs.swift.org/swift-book/documentation/the-swift-programming-language/patterns/ https://docs.swift.org/swift-book/documentation/the-swift-pr...)
- filleduchaos 3y agoI don't really understand the point of pointing this out. The GP already says that it's a simple feature that they're also surprised isn't available in more languages - nowhere did they claim that Apple invented it or that it's a super innovative thing or anything.
- bmitc 3y agoThe commenter mentioned: > it has so many simple features I love that I am sometimes surprised to find are missing in other languages and a few other things that led me to believe they were unaware of discriminated unions. There was an implication that this was a unique or novel feature in Swift. It's like someone being excited about Python's pattern matching, thinking Python came up with it and wishing other languages had it when it's a watered down, less useful version of that found in languages it ignored for 30 years.
- filleduchaos 3y agoI don't know, personally I think it is an immense leap of logic to look at someone's surprise that a simple feature is missing in [another] language and conclude that they're saying the feature is unique or novel.
- bmitc 3y agoI don't know how else you interpret what I quoted. And it's not a judgement.
- filleduchaos 3y agoRust has a borrow checker. I think it is unique/novel, and I definitely don't think it is simple. In fact, it's precisely because I think it is unique/novel that I very much am not surprised that it doesn't exist in other languages that I use. Why on earth would I be surprised that a feature I think was just invented isn't yet present in other things? That's not how the passage of time works. On the other hand, Rust also has first-class functions including closures. I do think that closures are a simple programming language feature, and I'm definitely surprised/put off when I write a language that doesn't have them (though these days I'm not sure there are any mainstream ones, now that Java and C++ both have them in the spec). Again it's precisely because I think of closures as the opposite of unique/novel that I am surprised at their absence. Why would I be surprised that a language does not have closures if I thought the Rust team just made them up? So yes, I have no idea how one would conclude that someone's surprise at a simple feature being unavailable indicates that they think the feature is unique or novel, other than just being a knee-jerk reaction.
- nozzlegear 3y agoF# is my “primary” programming language, I work with it daily and absolutely love it. That said, it doesn’t surprise me that people ignore it or don’t know about it given Microsoft’s own lack of attention and focus on it. Half the time it seems new dotnet features aren’t even compatible with F#. The day C# gets discriminated union types and true exhaustive pattern matching is the day I’ll have to think long and hard about how much more time I want to put into working with my beloved F#.
- Gibbon1 3y agoI strongly believe (waves hands while making incoherent small brained primate noises) that discriminated union types would be fabo for C as well. Example why it would be sweet. Compiler could spit out a warning if it's not sure the correct union type is being used. Like if the pet union has dog and cat. Cat has respawn set initially to 9. Dog doesn't have respawn. If you try to set respawn without checking if it's a cat compiler whines about it.
- pjmlp 3y agoThe C in CLR nowadays means C#, the Common has been lost long time ago, unfortunately.
- adamwk 3y agoHow is it stunted or limited?