Techie and toothy

Golang is Awful, Part 1: It has No Error Handling

A friend mentioned wanting to learn Golang, and I replied that I couldn't think of a worse programming language. 😅 But, learning a little will be good for job prospects. She asked why, and here's Part 1 / 3 of my answer. 🫣

Go is Java 1.1 without Exceptions

I realize this is a controversial statement.

Go is like Java 1.1 (circa 1994) but without exceptions. This morning (!) I stumbled on this example, completely organically, searching for a CLI app for Render. This ugly pattern shows up four times the short file:

services, err := client.Services().List(cmd.Context())
if err != nil { 
   return err
}

This is super-common, best-practices Go code. Every statement that can fail must turn into 3–4 tedious lines of code.

Notice how easy it can be to forget or mess up this error checking. There's nothing in the language forcing you to handle the errors.

Compare that to this Rust code doing the exact same Render API call:

let services = runtime.block_on(api::list_services(token))?;

Rust embodies the modern approach to error handling. First, the compiler will ensure that the programmer handles the error in some way. The function signature is also annotated as returning a Result — a union type which is either a real result or an error. And here, the programmer opted to use Rust's ? syntax for easy error handling: it will stop and return an error if that's what the function returned. Otherwise, the code proceeds as normal. Again, for emphasis: this Rust code will not compile without the ? (or some other explicit error handling).

In my opinion, the Go version is also too un-expressive to be a pleasure reading or writing. In other words, its purpose and behavior isn't immediately clear from looking at it.

So – the lack of error handling is a show-stopper for me. I expect a lot more help from the language in preventing errors. I also expect more readable code. Now, you might be fine with Go code like this. That's cool. Given the two open source libraries above, I'm choosing Rust.

Discuss...