3 ms·
> Alternatively, don't validate and then use the original. Instead, pull out the acceptable input and use that. Parse don't validate https://lexi-lambda.github
by Akronymus 2y ago
> Alternatively, don't validate and then use the original. Instead, pull out the acceptable input and use that.
Parse don't validate https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
- sfink 2y agoHeh. I wrote up my comment, and then thought "hey, I bet that's what that 'Parse don't validate' article meant, the one I never quite got around to reading." So I pulled it up — great article! — but then didn't post the link because it uses the type system to record the results of the parse. Whereas here, you'd probably parse from a string into another string. But philosophically I agree, that's exactly the relevant advice.
- Akronymus 2y agoparsing from a string to a string runs the risk of erroneously assigning the original value to the new string. Which kinda defeats the whole parsing, not validating. What would work is having a small object holding a readonly string which parses the original on creation, then becomes immutable.