• arc@lemm.ee
      ·
      1 year ago

      Swift and Rust have a far more elegant solution. Swift has a pseudo throw / try-catch, while Rust has a Result<> and if you want to throw it up the chain you can use a ? notation instead of cluttering the code with error checking.

      • barsoap@lemm.ee
        ·
        1 year ago

        The exception handling question mark, spelled ? and abbreviated and pronounced eh?, is a half-arsed copy of monadic error handling. Rust devs really wanted the syntax without introducing HKTs, and admittedly you can't do foo()?.bar()?.baz()? in Haskell so it's only theoretical purity which is half-arsed, not ergonomics.

        • arc@lemm.ee
          ·
          1 year ago

          You can say it's half-arsed if you like, but it's still vastly more convenient to write than if err != nil all over the place

        • m_f@midwest.social
          ·
          1 year ago

          It's not a half-arsed copy, it's borrowing a limited subset of HKT for a language with very different goals. Haskell can afford a lot of luxuries that Rust can't.

          • barsoap@lemm.ee
            ·
            1 year ago

            It's a specialised syntax transformation that has nothing to do with HKTs, or the type system in general. Also HKTs aren't off the table it's just that their theory isn't exactly trivial in face of the rest of Rust's type system but we already have GATs.

            It actually wouldn't be hard writing a macro implementing do-notation that desugars to and_then calls on a particular type to get some kind of generic code (though of course monomorphised), but of course that would be circumventing the type system.

            Anyhow my point stands that how Rust currently does it is imitating all that Haskell goodness on a practical everyday coding level but without having (yet) to solve the hard problem of how to do it without special-cased syntax sugar. With proper monads we e.g. wouldn't need to have separate syntax for async and ?

      • ennemi [he/him]
        ·
        edit-2
        1 year ago

        The language was designed to be as simple as possible, as to not confuse the developers at Google. I know this sounds like something I made up in bad faith, but it's really not.

        The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt. – Rob Pike

        "It must be familiar, roughly C-like. Programmers working at Google are early in their careers and are most familiar with procedural languages, particularly from the C family. The need to get programmers productive quickly in a new language means that the language cannot be too radical. – Rob Pike

        The infamous if err != nil blocks are a consequence of building the language around tuples (as opposed to, say, sum types like in Rust) and treating errors as values like in C. Rob Pike attempts to explain why it's not a big deal here.

      • silent_water [she/her]
        ·
        1 year ago

        a desperate fear of modular code that provides sound and safe abstractions over common patterns. that the language failed to learn from Java and was eventually forced to add generics anyway - a lesson from 2004 - says everything worth saying about the language.