4 ms·
I’m curious what your alternative is, given that Go famously also lacks sum types.
by mc10 6y ago
I’m curious what your alternative is, given that Go famously also lacks sum types.
- damnyou 6y agoYes, Go is a fundamentally broken language too. As is C++, as is C. Sum types are the absolute bare minimum a language must have for me to not consider it broken beyond hope. Go in particular is really unfortunate for a language so new. The language's weaknesses have dropped my estimation of its creators by several notches.
- Guthur 6y ago"I'm broken and can not use a language without Sum Types" There, I fixed it for you.
- damnyou 6y agoYes, that's possible. I would rather tear my eyes out than use a language without sum types. The benefits of sum types in being able to model arbitrarily complex domains are extraordinarily massive. Every language has product types. Every programmer understands how useful product types are. Why in the world would the same not apply to sum types?
- AnimalMuppet 6y agoYou sound like you have a hammer, and so every problem looks like a nail. Sum types can be useful. Other aspects of languages can be useful, too. Why fixate on that one? And if you're going to say that it's a minimum bar, well, some of the other features are missing in most languages that have sum types. Pick the language that has the total set of features that makes it easiest to write whatever program you're trying to write. Don't get locked in to focusing on only one feature.
- damnyou 6y agoYes that's why I write Rust. Our field has a terrible reputation for quality. In my estimation roughly 70-80% of that is directly or indirectly because of the lack of sum types. Directly: people don't have the right tools to make invalid states in their business logic unrepresentable. Indirectly: the lack of sum types results in broken null and error handling.
- Guthur 6y agoAt this stage I'm now convince you're trolling us all. Well done you had us all fooled :)
- damnyou 6y agoNot trolling. Entirely serious.
- bombela 6y agoCan anybody explain why the parent is being downvoted? We can argue on the percentage. But the point on the direct and indirect damages makes a lot of sense.
- AnimalMuppet 6y agoLate reply; I hope you see it. My reply is late because I had to think for a day first. So, my sincere congratulations - a post that makes me think for a day is much rarer than a post I agree with. To me, sum types for error handling are isomorphic to checked exceptions. They both let you do dual-track programming - separating the normal path from the error path. Both have compiler support for enforcement. But checked exceptions are no longer considered to be the answer. What went wrong? The problem turned out to be the programmers. They did at least two things that subverted checked exceptions. First, they silently ate exceptions (that is, had an empty catch block just to make the exception go away. This is the equivalent of having a sum type that is either an integer or Nothing, and a function. Rather than return the sum type, the function returns an integer. In the Nothing case, the function just returns 0. That's about the same as the empty catch block to not have to declare the exception in the function's return type. The second way checked exceptions went wrong was the opposite. When a function could throw Exception1, Exception2, Exception3, and Exception4, it was tempting to just declare it as throwing Exception (the base class). In the same way, a function that gets SumType1 back from one function, SumType2 back from another function, and SumType3 from a third function may return the sum of the sum types. It becomes an Everything type. In both cases, the problem was that programmers were lazy. But here we are 20 years later, and programmers are still lazy. Until the programmers change, sum types won't fix things any more than checked exceptions did.
- exclusiv 6y agoAlso - "I refuse to use most languages that have been used to solve a shit ton of problems". Or, "I will not use any language which made software eat the world"
- timmattison 6y agoDoes the Either type from the vavr library for Java cover this? https://www.baeldung.com/vavr-either https://www.baeldung.com/vavr-either
- damnyou 6y agoHaving a type available in an optional library is not the same thing as having them baked in from the beginning. The absence of sum types warps a language in grotesquely terrible ways, such as Go's err != nil patterns or Java's exception system and visitor patterns.
- PhantomBKB 6y agoI wouldn't say no, because it's built with the right spirit in mind. But at the same time, it's different from languages have native support for sum types. Advantage of sum type is that it can be matched exhaustively like an enum, but at the same time it's flexible to contain any data like a data class.
- benibela 6y agoC has unions What more do you need?
- damnyou 6y agoAre unions used for error handling and null checking? No? Then they're not very useful.