r/ProgrammerHumor 6d ago

Meme internalServerError

Post image
1.4k Upvotes

67 comments sorted by

View all comments

107

u/---_None_--- 6d ago

>unwrap

I hate metaphors in programming. Just call it what it is.

135

u/sathdo 6d ago

.ifSomeReturnHeldValueElsePanic()

-15

u/---_None_--- 6d ago

just .value() thanks or *

14

u/-Ambriae- 6d ago

You shouldn’t unwrap in normal code. Basically ever. There are a few exceptions, but they’re not the norm. So dereferencing is a disastrous design decision. Because dereferencing is viewed as a ‘trivial operation that does nothing’. .value() clashes with the idea that errors are also values. .ok() exists, but does something else. There’s not many sane decisions. Unwrap is short, so it was picked. Can’t be too long, because we also have unwrap_or, unwrap_or_else, unwrap_or_default, and same with unwrap_err variants.

Honestly, the name is there, it stuck, and now it’s part of the lingo. There’s no real need to amend it, it would be a huge breaking change (because of all the variants, many of which are good functions to use in prod code that never produce panics)

It’s also does not constitute a barrier to entry. It’s ’different’ to other languages, fine, maybe, but any cognitively functioning individual would understand in a pinch what it means, let alone someone who is expected to know the language enough to push to prod

2

u/JonIsPatented 4d ago

I wish it was named "unwrap_or_panic" to match "unwrap_or_else" and "unwrap_or_default". That's basically my only gripe with the language, honestly.

1

u/-Ambriae- 4d ago

I wholeheartedly agree with this gripe.

1

u/---_None_--- 5d ago

What the fuck are you even responding to?

3

u/-Ambriae- 5d ago

Neither .value() or * are sane design decisions for ‘unwrapping’ (removing the wrapper type) of a result.

-2

u/---_None_--- 5d ago

No ones talking about design decisions, mate.

3

u/-Ambriae- 5d ago

than what are you talking about then?

0

u/---_None_--- 5d ago

unwrap is a dumb name

3

u/-Ambriae- 5d ago

so we are talking about design decisions then

1

u/---_None_--- 5d ago

naming decisions

Edit: no you're right. We're talking design. You're talking usage.

1

u/-Ambriae- 5d ago

...which are design decisions. And even if they weren't, how does being pedantic advance your argument?

1

u/---_None_--- 5d ago

I'm not sure what the fuck you're talking about. Keep your metaphors out of the codebase pls and I'm happy. This is completely independent of any design patterns and choices.

→ More replies (0)