News for hackers. Stuff that matters.
Re:Views on Error Handling by dllthomas on Saturday July 18, 2020 @05:53PM (#23885162)
Can you name a language/ecosystem that gets it right?
Re:Views on Error Handling by dinosaurdynasty on Saturday July 18, 2020 @06:19PM (#23885330)
Rust seems pretty close to this (with Result<T, E>), though there is also the panic system.
Re:Views on Error Handling by platz on Sunday July 19, 2020 @12:01AM (#23886896)
it's trivial in any language to define and use a Result<T, E> type.
Re:Views on Error Handling by saagarjha on Sunday July 19, 2020 @03:41AM (#23887715)
No, not really. Languages that don’t really embrace such a type can usually never make its use ergonomic. Adding such a construct to C or Java would be “trivial” but its use would be exceedingly painful.
Re:Views on Error Handling by The_rationalist on Sunday July 19, 2020 @04:09AM (#23887839)
Here's an example of a result type in Kotlin implemented as a library monad. (the language is getting an official one but is currently less featureful than this lib)

You can use exception or Result depending on when it makes the most sense and this is the best of both worlds. https://github.com/kittinunf/Result

Re:Views on Error Handling by saagarjha on Sunday July 19, 2020 @04:49AM (#23887983)
Swift had a bunch for a while too, but it’s getting an official one as well. Again, that’s only because the language provides the right tools for it to exist, in languages where you don’t have this you’re going to have a very hard time trying to add these things in.
Re:Views on Error Handling by aw1621107 on Sunday July 19, 2020 @03:03AM (#23887565)
That depends a lot on what you mean by "use". Pretty much every commonly used language would be able to define something that can hold one of two things and provide ways to determine which one is present and retrieve one of the two options, but comparatively few are going to be able to provide the same guards against accidental or intentional misuse that pattern matching gets you.
Re:Views on Error Handling by jjjensen90 on Saturday July 18, 2020 @05:58PM (#23885196)
Though I don't think it's perfect, languages like Go that treat errors as simply another type and you check as a return value do get closer to treating errors and success symmetrically versus an exception throwing and typing system like some other languages.
Re:Views on Error Handling by monocasa on Saturday July 18, 2020 @06:01PM (#23885212)
Building on that, the ADT languages with full option types here are fantastic here, because the shape of the data in each case can be taught to the compiler.
Re:Views on Error Handling by vvanders on Saturday July 18, 2020 @06:25PM (#23885363)
Erlang / OTP.