#post
programming-parse-incoming-data-instead-of-only-validating-it
A function that only validates will output a boolean
(or nothing if “didn’t raise an error” is your function’s approach to indicating validity). In contrast, a function that parses outputs your type or null. In the process of parsing into your type, you validate as well. The benefit is you get to capture the information provided by your validation logic in your new type.
- Comment on my “label unknown and then validate thoroughly” post: “A step up on validating is to actually parse the payload. It makes it much easier to ensure complex types are properly handled and a much easier diagnostic on the error path.” — Why Unknown Types Are Useful : r/programming
- Here’s another more detailed expansion on that idea from the same Reddit discussion: https://www.reddit.com/r/programming/comments/1eewn7r/comment/lfhz3cx/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
- Parse, don’t validate - Alexis King article everyone references as the source of this good idea