Comment by dllthomas

5 years ago

Can you name a language/ecosystem that gets it right?

Rust seems pretty close to this (with Result<T, E>), though there is also the panic system.

  • it's trivial in any language to define and use a Result<T, E> type.

    • 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.

      2 replies →

    • 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.

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.

  • 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.