167
submitted 6 days ago* (last edited 6 days ago) by qaz@lemmy.world to c/programmer_humor@programming.dev

Don't say anyway, say anyhow

you are viewing a single comment's thread
view the rest of the comments
[-] magic_lobster_party@fedia.io 38 points 6 days ago

Unwrap means it forces to evaluate the result as an ”ok value”. If it’s an ”error value”, it will crash. It’s a bad practice to rely on it, as it’s one of the most common ways a Rust programs can crash.

Rust offers many options to handle errors that don’t risk crashing. For example, unwrap_or_default, which means ”if it’s an error value, use the default value for this type, such as 0 for integers”

[-] Korne127@lemmy.world 16 points 6 days ago

I mean using unwrap is not bad practice if the value is guaranteed to not be none, which can happen frequently in some applications.

[-] mobotsar@sh.itjust.works 4 points 5 days ago* (last edited 5 days ago)

If it's guaranteed to not be None, why is it an Option?

[-] emilgardis@lemmy.ml 3 points 5 days ago

Here's a bad example but hopefully captures the why. https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=43d055381e7bb52569c339d4526818f4

We have a condition we know must be satisfied (the option will always be Some), but cant prove in code.

load more comments (2 replies)
load more comments (3 replies)
load more comments (6 replies)
this post was submitted on 01 Aug 2025
167 points (97.2% liked)

Programmer Humor

25513 readers
2345 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 2 years ago
MODERATORS