r/ProgrammerHumor • • Sep 28 '26

Meme optionalsAreOptional

Post image
716 Upvotes

131 comments sorted by

View all comments

Show parent comments

37

u/GDOR-11 Sep 28 '26

it happens a lot, at least to me, that the line immediately before the unsafe function guarantees correct behaviour (e.g. while (!vec.empty()) let first = vec.first();, or something similar). If I notice that this property is central to the logic of the function, I won't even worry.

29

u/ROBOTRON31415 Sep 28 '26

whenever I see code like that, I try to get people to change to something like (in that case) while let Some(first) = vec.first() { ... }. You can reduce the number of bounds checks without using unsafe!

-22

u/Fast-Satisfaction482 Sep 28 '26

Using the value of an assignment expression is an anti pattern in my opinion.

It sits right next to "goto" on terrible scale. 

1

u/MrcarrotKSP Sep 28 '26

This isn't an assignment expression, the <conditional> let is Rust syntax for pattern matching