4 ms·
They'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 majorit
by akavi 7y ago
They'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++.