Hacker News new | ask | show | jobs
by fiatjaf 3212 days ago
In Go there are two ways you can handle wrong things happening:

  - return an error
  - panic
What is the recommended, best, pretty, beautiful way? Return an error. Nobody uses panic.

Javascript Promises are equivalent to that.

If you want to stop the main program, call process.exit(). That would be the equivalent of panic.

1 comments

I don't think it is beautiful. This fills program with lots of unnecessary `if`s for checking results of each call. Also, it prevents one from chaining functions like a(b(x)).
Yeah, you're right. Not beautiful and prevents chaining. But works like a charm, don't you think?

Chaining functions is for functional people. Go is proudly imperative.