this post was submitted on 15 May 2024
243 points (88.3% liked)

Programmer Humor

19171 readers
1484 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] sunbeam60@lemmy.one 4 points 4 months ago* (last edited 4 months ago) (1 children)

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 4 months ago (1 children)
[–] sunbeam60@lemmy.one 2 points 4 months ago

Well, different floats for different boats I suppose.