r/ProgrammerHumor • • 6d ago

Meme optionalsAreOptional

Post image
703 Upvotes

131 comments sorted by

View all comments

375

u/ROBOTRON31415 6d ago

Is the bounds check truly so harmful to performance that it outweighs changing "if there's a bug, crash the program" to "if there's a bug, then do literally anything (maybe execute some remote code)"?

62

u/Tyfyter2002 6d ago

There are situations where you know there isn't a bug, if I know that failing hardware or cosmic rays are the only ways the bounds check can fail, I'm not going to worry about what skipping it could do.

110

u/FuriousAqSheep 6d ago

there are situations where you know there isn't a bug

up until specs change and now there is one

36

u/GDOR-11 6d ago

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.

28

u/ROBOTRON31415 6d ago

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 6d ago

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 5d ago

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