622
submitted 11 months ago by jroid8@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] itslilith@lemmy.blahaj.zone 2 points 11 months ago

you could take a look at what Rust is doing with the Option enum. Superficially it looks similar to using null, but it actually accomplishes something very different.

A function that classically would return a value, say an int, but sometimes returns null instead, becomes a function that returns an Option. This forces explicit handling of the two cases, namely Some(value) or None. This way, it is next to impossible to try to do an operation on a value that does not exist.

this post was submitted on 08 Dec 2023
622 points (96.4% liked)

Programmer Humor

32509 readers
419 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS