4 ms·
It is not so much a matter of lack of type safety, it is forgetting to implement an application requirement. Even an advanced type system capable of formal pro
by randomdata 3y ago
It is not so much a matter of lack of type safety, it is forgetting to implement an application requirement.
Even an advanced type system capable of formal proofs isn't going to help you if you've forgotten the requirement when defining the types. And if you are using a language with a lesser type system (Go, Rust, any language you are likely to use in the real word), and haven't forgotten the requirement, then you would have encoded that knowledge in tests instead, making the forgetfulness in implementation ultimately immaterial. After all, there is no practical difference between learning that you forgot to implement logic by the compiler telling you or the test suite telling you.
So, we can infer that the OP is talking about where one straight up forgot about the requirement from start to finish. I'm skeptical that there is any technical solution to that problem, but sum types most certainly isn't it.
- vacuity 3y agoThere is a point at which even dependent typing won't save you, but sum types are a useful tool to reduce negligence. Don't let perfect be the enemy of good.
- randomdata 3y agoSum types are useful tool, but they are not helpful in this particular case. There is nothing about sum types that would help avoid this problem in the slightest. Perfect need not be the enemy of good, but good is not equivalent to not even trying. This is not a general "wouldn't it be nice of Go had..." thread. We are talking about a specific problem.
- vacuity 3y agoI'm not really sure what your point is then. We should have comprehensive tests and therefore error checking isn't special compared to other programming mistakes? I think we should both have tests (don't skimp on them if given time, of course) and use tools like sum types to write more robust programs from the get-go. Errors can even be treated like other values using sum types; that raises the bar universally instead of just improving error checking.
- randomdata 3y agoThe point is to stay on topic. In what way do you believe sum types solve the problem being discussed?
- vacuity 3y agoIf you're going to invoke some abstract "the programmer doesn't know what they're doing" situation, I'm not sure how to continue this discussion. Even testing may not help in that case. Things are going to slip through the cracks. Having features like sum types is a way to generally reduce the likelihood of such semantic errors. Besides, the original topic was that Go doesn't make its error handling very foolproof. Sum types help with that and don't make error handling special, so I really don't see your point. Why not write everything in Brainfuck then? Everything is uniform and simple. Well, it's simple to the point that it's way too easy to make mistakes.
- randomdata 3y agoThe original topic was, stated quite explicitly, that it is easy to forget to handle errors in Go. There is nothing about sum types, as defined, that addresses that concern. Like we established in my very first comment, well before you even showed up, the handling forgetfulness problem exists for all types. That would include a hypothetical (tagged) union type. I did question if you were using some other definition of sum types, as there isn't a great consensus on what sum types actually mean, but you did confirm you were thinking of tagged unions... But it must be that you didn't actually mean tagged unions. What is the definition of sum types that you are using here that would help with the stated problem?
- vacuity 3y agoThere may be a misunderstanding. I say "sum type" to mean something along the lines of Rust's enum: a value stores both a tag and its data, and pattern matching distinguishes the variants (like a switch statement). It's a tagged union where the interpretation of the tag is managed by the compiler. The underlying value can't be used without extracting the variant with pattern matching. Even if the success and failure variants both contain an integer, you can't add an integer with this value.