4 ms·
They are adding generics so why not do something like Rust does (https://learning-rust.github.io/docs/e3.option_and_result.html https://learning-rust.github.io/
by notus 7y ago
They are adding generics so why not do something like Rust does (https://learning-rust.github.io/docs/e3.option_and_result.html https://learning-rust.github.io/docs/e3.option_and_result.ht...)
- monocasa 7y agoThat would take adding enums, which they aren't doing.
- akavi 7y agoFor anyone else who was confused: "enums" is what Rust calls sum types.
- stcredzero 7y agoenums/sum type functionality could be implemented using Interfaces in golang.
- akavi 7y agoNo, they can't. At least not in a type-safe way.
- stcredzero 7y agoJust define an Interface which includes the implementation of thisIsMySumTypeAsAnInterface() Then only types which implement that are in that Interface. There's your enum/sum type. Not ironclad, but safe enough to get things done.
- stouset 7y agoIt also doesn't actually accomplish what people are talking about using sum types for. There's also no language support for ensuring you've exhaustively matched every variant.
- crimsonalucard 7y agoThe error/maybe/whatever monad with pattern matching is not only the most elegant solution, it is the most robust solution. No other solution allows the compiler to catch a runtime error at compile time.
- notus 7y agoYeah I agree. Surprises me more languages don't adopt or popularize this approach. I guess people like having runtime errors.
- marcosdumay 7y agoPeople mostly do not mind runtime errors, downtime, data corruption or loss. It's mindblowing, but you can watch the reaction of most people, there is almost never an step of "let's find what the problem actually was and make sure it doesn't repeat later".
- frou_dh 7y agoSame deal with people parroting market-segmentation blather about not """needing""" ECC RAM.