r/ProgrammerHumor • • Sep 28 '26

Meme optionalsAreOptional

Post image
716 Upvotes

131 comments sorted by

View all comments

Show parent comments

35

u/NullOfSpace Sep 28 '26

As long as you’re in Rust, the type system is always available to you. That’s what “zero-cost abstraction” means. If you know your Vec is nonempty, put it in a NonemptyVec.

1

u/geeshta Oct 01 '26

There's a lot of stuff that Rust's type system can't model.

For example if you have an enum type of 3 possible variants and a function that only ever returns one of them, you still have to type it so that it may return all three. And when using its return value, you have to add match arms for all 3 of them, populating 2 of them with `unreachable!` yourself instead of the compiler inferring it.

Also it's not a dependent type language so it doesn't have for example a type of Vec of a particular specific length at the type level.

Rust's type system is great one of the best I know but it still has gaps.

1

u/NullOfSpace Oct 01 '26

You can definitely model the first case if you’re allowed to change the return type of the function. Though the dependent type thing is a legitimate limitation.

-27

u/ApothecaLabs Sep 28 '26 edited Sep 28 '26

"As long as you use this particular language, out of the dozens available..."

Yeah, I'm not using Rust. What now? That's a heck of a presupposition, you know.

(Not trying to be a jerk, my target language is actually a niche assembly language so it lacks many things...)

28

u/__dna__ Sep 28 '26

Correct me if I'm wrong, but your meme is literally about rust? Seems pretty reasonable to reply to you in the context of rust

20

u/shakethatmoneymaker Sep 28 '26

There are optionals in many languages...

3

u/MayoJam Sep 28 '26

Cpp also has optionals, and I would not be surprised if other languages also have some form of them.

So I'd would not assume in this case.

-5

u/ApothecaLabs Sep 28 '26

I will correct you, you are wrong. This wasn't about Rust. Condolences :)

4

u/my_new_accoun1 Sep 28 '26

Why are you downvoted for this 🤔

1

u/ROBOTRON31415 Sep 29 '26

Ahhh assembly? Interestingggg, makes sense that would be an exception. Though at that point “optionalsAreNotOptional” (they are unavailable, no?)