Discussion about this post

User's avatar
T C Oliveira's avatar

From my own personal experience dealing with languages that handle this on three different ways:

In C#, you have exceptions and need to try..except them or be bugged by unhandled exceptions. Knowing what can fail requires some digging and it's often necessary to go through additional documentation when the API is not clear or is a black box;

In Go, by convention, errors are types and there's no try..catch/except construct. It feels weird, but over time it makes you consider errors in your design. "An error happened" becomes more important than "what error happened" over 90% of scenarios, and the difference from an error to an expection is also made obvious by making exceptions panics. The disadvantage here is that you need to adopt a "hive mindset" to do this thing property and maybe that's why Go peeps are seen as members of a cult;

In Scala, you follow the monadic approach towards exceptions. It's very elegant, reads clearly, follows a great flow. But it becomes difficult for people that need to read the code later, if they need to touch a certain code path that can raise an intermediate exception.

---

As such, from the standpoint of "It's more important to deliver features using simple code that people will be able to read later, and that allows us to move quicker", Go is still my personal choice, although it looks kinda "primitive" (and that's the whole point of the language). For the following reasons:

- readable code for posterity is more important than clever code;

- clever code makes you feel good once you write it, but becomes a burden once you have to return to it;

- for the same reason that we read from left to right, it's important to understand execution flow from beginning to end. The various `if err = nil` feel weird, but we are reading a description of what our program is supposed to do, and errors are part of that description.

---

Regardless, as always, great article!

Expand full comment
1 more comment...

No posts