News for hackers. Stuff that matters.
Re:C’s Biggest Mistake by kaashif on Sunday July 02, 2023 @09:50PM (#36567757)
I think most of the time people really want a sum type, NOT a tuple. i.e. you can get back either a value OR an error, but not both. In Go, there's the pattern of returning nil, err, which is a hint that we really want a sum type there.

> In most languages that don't support multiple return values, both problems are solvable with templates or local equivalent

I don't really see the difference between tuples in C++ and multiple return values in Go (since you cite C++ as a language that doesn't have multiple return values).

    val, err := do_something()
or

    auto [val, err] = do_something();
What's the real difference there? Syntactic sugar?
Re:C’s Biggest Mistake by GeneralMayhem on Tuesday July 04, 2023 @09:55PM (#36594703)
I agree, you really want a sum, not a tuple - that's why my example was absl::StatusOr<T>, not std::pair. But a tuple plus tooling support (e.g., linters in Go that don't allow you to not use the returned error value) can emulate a sum type.