4 ms·
> I could not believe they had not been part of any prior language I'd learned. Huh? They're part of Pascal (known as variant records) and plenty of other lang
by zozbot234 7y ago
> I could not believe they had not been part of any prior language I'd learned.
Huh? They're part of Pascal (known as variant records) and plenty of other languages besides. It's mostly C that lacks them, and even then you're just expected to implement them yourself, for maximum efficiency.
- akavi 7y agoThey're not present in the dominant statically typed languages (C/C++/C#/Java/Go) and not really a thing in dynamic languages generally, and so the vast majority of programmers never encounter the concept.
- pmontra 7y agoWell, Pascal has been dominant for a short time before C and its family really took off. But that was such a long time ago that I kind of forgot about it. C (without ++) was nice because you could write code without too much boilerplate compare to Pascal and it was noticeably faster (computers were slow.) However any mistake with pointers could crash the computer if it was a DOS PC and not a UNIX workstation.
- LessDmesg 7y agoThis might help explain why the dominant statically-typed languages are so hated. It's easy to choose Python when those languages are too clumsy to express a closed tagged union. This gives an undeserved bad rep to statical typing as a whole, when the solution is obvious to anyone familiar with algebra. Sum types are to product types what addition is to multiplication: if your language has one, why not have the other one? Answer that one, Bjarne Stroustrup!
- thestoicattack 7y agoC++ has std::variant, but that's pretty new.
- Sniffnoy 7y agoMy understanding is that's not really a sum type, though -- e.g., you couldn't use it to add a type to itself, only to add distinct types to each other.
- edflsafoiewq 7y agoNo, you can add a type to itself (that is a pain in the ass though). You might be thinking of the fact that it may not hold a value (eg. if an exception is thrown while moving into it), but they made it as close to a sum as they could given the nature of C++.
- reificator 7y ago> Huh? They're part of Pascal (known as variant records) and plenty of other languages besides. It's mostly C that lacks them, and even then you're just expected to implement them yourself, for maximum efficiency. "plenty of other languages besides" doesn't matter if those languages aren't being used in practice. Let me list off the top 10 languages (incl markup) from the most recent Stack Overflow survey, specifically the Professional Developers tab. https://insights.stackoverflow.com/survey/2019#technology-_-programming-scripting-and-markup-languages https://insights.stackoverflow.com/survey/2019#technology-_-... * JavaScript * HTML/CSS * SQL * Python * Java * Bash/Shell/PowerShell * C# * PHP * TypeScript * C++ You can argue about the demographics of Stack Overflow or the bias in users who actually respond on these surveys or a million other things. But based on job postings I've seen in the last several years, I'd wager this list is pretty accurate.
- gimboland 7y agoYeah. You're not wrong. Sadly, while HN is full of people of great technical expertise, it's also full of people whose knee-jerk reaction to reading _anything_ here is to think of how they can say it's wrong, preferably in a way that implies or explicitly states that they're bigger experts than the person they're replying to. I find it very off-putting, personally, but I keep wading through the crap because (thankfully) that's not the whole story.
- fauigerzigerk 7y agoSwift is being used in practice and will most likely see more use in the future as Objective-C fades.
- reificator 7y agoIf you follow the link you'll find Swift is already above Objective-C on that survey, just that neither of them made the top ten.
- fauigerzigerk 7y agoI did follow the link, but I disagree with your conclusion that being used by at least 6.6% of respondents to make apps for hundereds of millions of users amounts to "not being used in practice".
- AnimalMuppet 7y agoIt's been a long time since I did anything with Pascal, but if I recall variant records correctly, they're not very different from C's unions. In particular, I don't recall variant records having anything like totality checking. I don't even recall it having anything that could tell you what kind of thing it currently holds. But as I said, it's been a long time...
- saghm 7y ago> They're part of Pascal (known as variant records) and plenty of other languages besides. It sounds like GP is saying they had never used of those languages beforehand. I'm not sure why would be so surprising given that it doesn't accompany any other information like "and I had used 20 other languages before it".
- Roboprog 7y agoC has unions, which are similar to Pascal’s variant records, though without an explicit out of band discriminant.