qaz@lemmy.world to Programmer Humor@programming.devEnglish · edit-22 days agoSlapping on a .expect is also error handling!lemmy.worldimagemessage-square26fedilinkarrow-up1162arrow-down15file-text
arrow-up1157arrow-down1imageSlapping on a .expect is also error handling!lemmy.worldqaz@lemmy.world to Programmer Humor@programming.devEnglish · edit-22 days agomessage-square26fedilinkfile-text
minus-squaremobotsar@sh.itjust.workslinkfedilinkEnglisharrow-up4·edit-21 day agoIf it’s guaranteed to not be None, why is it an Option?
minus-squareemilgardis@lemmy.mllinkfedilinkEnglisharrow-up3·1 day 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.
minus-squaremarcos@lemmy.worldlinkfedilinkarrow-up2·edit-21 day 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.)
If it’s guaranteed to not be
None
, why is it anOption
?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.
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.)