You are viewing a single thread.
View all comments View context
0 points

Yeah but Go has the best error handling paradigm of any programming language ever created:

ret, err := do_thing()

if err != nil {
    return nil, err
}

Don’t you just love doing that every 5 lines of code?

permalink
report
parent
reply
0 points

I don’t like the rust way either. But at least you can unwrap

permalink
report
parent
reply
0 points

With some sprinkle of libraries such as anyhow and thiserror the Rust errors become actually pleasant to use. The vanilla way is indeed painful when you start handling more than one type of error at a time.

permalink
report
parent
reply
-1 points

Exactly this. Anyhow makes error handling in rust actually a joy. It’s only something you need to consider if you’re writing a library for others to use, and in that case, it’s good that rust forces you to be very very explicit

permalink
report
parent
reply
0 points
*

I do think Zig is better for this kind of thing.

const ret = try do_thing();

if( ret ) | result | {
   do_something_with_result(result);
}

The try keyword returns any error up; the if-unwrap works with what came out of a successful call. Normally you wouldn’t have both, of course.

do_thing would be defined as a union of an error (a distinct kind of type, so it can be reasoned about with try, catch and unwrapping) and the wrapped return value.

permalink
report
parent
reply
-1 points

That syntax looks atrocious

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 7K

    Monthly active users

  • 730

    Posts

  • 11K

    Comments