Comment

Comment by GeneralMayhem

1. In a world without templates/generics, you have to manually define a different such struct for every possible return type. Can be macro'd at the function definition, but it's ugly.

2. Without first-class support, it's very difficult to assert that the error is actually being checked. Consider:

    int someVal = getSomeVal(...).v;
    doSomethingWith(someVal);
vs.

    (int someVal, error e) = getSomeVal(...);
    doSomethingWith(someVal);
Which is easier to catch at code-review time, or even at linter time?

In most languages that don't support multiple return values, both problems are solvable with templates or local equivalent - see, for instance, absl::StatusOr for C++ (https://abseil.io/docs/cpp/guides/status).

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton