News for hackers. Stuff that matters.
Re:On the uses and misuses of panics in Go by atombender on Thursday August 09, 2018 @11:22PM (#17730470)
There's a major downside to the multi-value returns compared to sum types: They can't be chained. You have to assign the two result values to two separate variables:

  s, err := readFile()
There's no way to build something like this:

  readFile().then(func(s string) { ... })
Well, you can build it by having readFile() return some object with a then(), but without generics you can't build anything remotely ergonomic here.

(Actually, Go has an interesting quirk where multi-value return values can be passed as arguments to a function, so this is allowed:

  func handleErrors(s string, err error) { ...}
  func readFile() (string, error) { ... }
  func main() {
    handleErrors(readFile())
  }
Unfortunately, there's no way to build a generic chaining mechanism with this, since you'd have to have a handleErrors() for every possible return type combination.)

There are no comments on this comment yet.