←back to thread

Parse, Don't Validate (2019)

(lexi-lambda.github.io)
389 points melse | 1 comments | | HN request time: 0.212s | source
Show context
wodenokoto ◴[] No.27640366[source]
When I think of validation I think of receiving a data file and checking that all rows and columns are correct and generating a report about all the problems.

Does my thing have a different name? Where can I read up on how to do that best?

replies(4): >>27640640 #>>27640784 #>>27640888 #>>27642921 #
quickthrower2 ◴[] No.27640640[source]
I thought of input validation for web forms. Similar thing I guess. In Haskell you can create a type that you know is a validated email address but you still need a validation function from String -> Maybe Email to actually validate it at runtime
replies(2): >>27640914 #>>27641008 #
1. jacoblambda ◴[] No.27640914[source]
That's just a parser though. Like described in the post, parsers sometimes can fail but importantly they always pass along the result if they succeed. Validation functions on the other hand only validate that said data is valid.

The argument is that if you need to interact with or operate on some data you shouldn't be designing functions to validate the data but rather to render it into a useful output with well defined behaviour.