246
Go vs Rust learning (programming.dev)
you are viewing a single comment's thread
view the rest of the comments
[-] Technus@lemmy.zip 43 points 6 months ago

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?

[-] kaffiene@lemmy.world 6 points 6 months ago

I actually reasonably like Go. It's simple and pragmatic but I fucking loathe its error handling. To me it just replicates one of the worst features of C

[-] txmyx@programming.dev 4 points 6 months ago

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

[-] TheEntity@lemmy.world 20 points 6 months ago

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.

[-] Fal@yiffit.net 5 points 6 months ago

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

[-] sunbeam60@lemmy.one 4 points 6 months ago* (last edited 6 months ago)

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.

[-] Fal@yiffit.net 5 points 6 months ago
[-] sunbeam60@lemmy.one 2 points 6 months ago

Well, different floats for different boats I suppose.

[-] pipe01@programming.dev 2 points 6 months ago

Honestly, I do

[-] Shareni@programming.dev -1 points 6 months ago

It's not pretty, but it's uniform, obvious, and easy to understand.

go is good grug friend who chase away complexity demon by limit damage of big brain developer

this post was submitted on 15 May 2024
246 points (88.4% liked)

Programmer Humor

19564 readers
1042 users here now

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

founded 1 year ago
MODERATORS