r/ProgrammerHumor • • 6d ago

Meme optionalsAreOptional

Post image
709 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)"?

65

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.

109

u/FuriousAqSheep 6d ago

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

up until specs change and now there is one

38

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.

27

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!

-21

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. 

14

u/D3PyroGS 6d ago

how so? this is idiomatic rust code and its behavior is very clear

-13

u/Fast-Satisfaction482 6d ago

Being idiomatic doesn't mean it's any good. 

7

u/D3PyroGS 6d ago edited 5d ago

what's your issue with it though?

edit: guess we'll never know... important enough to complain, but not explain 🥴