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

Programmer Humor

19589 readers
492 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
[–] [email protected] 4 points 6 months ago* (last edited 6 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.

[–] [email protected] 5 points 6 months ago (1 children)
[–] [email protected] 2 points 6 months ago

Well, different floats for different boats I suppose.