qaz@lemmy.world to Programmer Humor@programming.devEnglish · edit-23 months 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-23 months agomessage-square28linkfedilinkfile-text
minus-squareKorne127@lemmy.worldlinkfedilinkarrow-up0·3 months agoI mean using unwrap is not bad practice if the value is guaranteed to not be none, which can happen frequently in some applications.
minus-squareqaz@lemmy.worldOPlinkfedilinkEnglisharrow-up0·3 months agoA good example would be regex. After validating it when writing the program it should always compile.
minus-squaremobotsar@sh.itjust.workslinkfedilinkEnglisharrow-up0·edit-23 months agoIf it’s guaranteed to not be None, why is it an Option?
minus-squareemilgardis@lemmy.mllinkfedilinkEnglisharrow-up0·3 months 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-up0·edit-23 months 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.)
I mean using unwrap is not bad practice if the value is guaranteed to not be none, which can happen frequently in some applications.
A good example would be regex. After validating it when writing the program it should always compile.
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.)