3
you are viewing a single comment's thread
view the rest of the comments
[-] gnus_migrate@programming.dev 4 points 1 year ago

I went into this with an open mind, then I saw the rant about error handling and I closed the article immediately.

Rusts error handling in combination with eyre/anyhow is the most pleasant error handling I have used in any language. You know exactly which lines can return errors, you can very quickly propagate them and attach context so that you can quickly troubleshoot later on, and it's completely natural and unintrusive. No figuring out whether you already logged the error somewhere else, no inconsistent handling of them, it's one library that does everything for you and you never have to think about it.

The go example is comparatively awful. You are forced to handle the error at each stage, and it runs into the same problem as exceptions where you're not really sure at which point you actually handled the error among other things.

[-] wilk@masto.bike 0 points 1 year ago

@gnus_migrate @nebiros In Go we consider errors as values and not fatal or exceptions. For example sql.ErrNoRows , io.EOF, custom... It's why they are returned and used like any other values.

[-] gnus_migrate@programming.dev 2 points 1 year ago

The difference is that you can't have a generic mechanism in Go for error handling. It's basically up to the programmer, and every if error != nil line is a potential source of bugs.

Errors are values in rust too. There are a couple of differences, like the ? syntax, rust returning a value or an error instead of a value and an error (or nil) for example, but everything you wrote applies to rust as well.

this post was submitted on 16 Jul 2023
3 points (61.5% liked)

Golang

0 readers
1 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS