qaz@lemmy.world to Programmer Humor@programming.devEnglish · edit-221 days agoSlapping on a .expect is also error handling!lemmy.worldimagemessage-square28linkfedilinkarrow-up11arrow-down10file-text
arrow-up11arrow-down1imageSlapping on a .expect is also error handling!lemmy.worldqaz@lemmy.world to Programmer Humor@programming.devEnglish · edit-221 days agomessage-square28linkfedilinkfile-text
minus-squaremobotsar@sh.itjust.workslinkfedilinkEnglisharrow-up0·edit-221 days agoIf it’s guaranteed to not be None, why is it an Option?
minus-squaremarcos@lemmy.worldlinkfedilinkarrow-up0·edit-221 days agoOh, it can happen when you do calculations with compile-time constants… But the GP’s claim that it’s a “frequent” thing is suspect. (Crashing is also useful when you are writing and-user applications, but you’ll probably want .expect like in the meme.)
minus-squareemilgardis@lemmy.mllinkfedilinkEnglisharrow-up0·21 days agoHere’s a bad example but hopefully captures the why. https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=43d055381e7bb52569c339d4526818f4 We have a condition we know must be satisfied (the option will always be Some), but cant prove in code.
If it’s guaranteed to not be
None
, why is it anOption
?Oh, it can happen when you do calculations with compile-time constants…
But the GP’s claim that it’s a “frequent” thing is suspect.
(Crashing is also useful when you are writing and-user applications, but you’ll probably want .expect like in the meme.)
Here’s a bad example but hopefully captures the why. https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=43d055381e7bb52569c339d4526818f4
We have a condition we know must be satisfied (the option will always be Some), but cant prove in code.