Re:Parsix: Parse Don't Validate
by billytetrud on Saturday May 15, 2021 @05:18PM
(#27169119)
Makes sense. It just seems like parsing is kind of a separate issue and shouldn't be entangled with the concept of input validation.
Interesting, would you mind explaining why parsing and validation are two different concerns?
Re:Parsix: Parse Don't Validate
by billytetrud on Sunday May 16, 2021 @04:05PM
(#27176571)
When I think of "parsing" I'm thinking of string parsing. But for example, validation of a number being in range or an obect containing a correct set of properties is not in the realm of string parsing, but is in the realm of validation.
In that sense, using types is only one way to do this, but you could model that in other ways. For example:
And now you could have: }Now types are a convenient way to do this that also gives you static checking for it, but I believe the idea is more to model that things were validated and expects validated input or fail.
That allows you to push all validation at the boundary, and make sure that no one ever forgets to validate the input, because if they do, the inner functions will fail reminding the caller: Please remember to validate this!