|
|
|
|
|
by mtlynch
867 days ago
|
|
Thanks for that explanation! I hadn't appreciated that aspect of "parse, don't validate," before. But even with that understanding and from re-reading the post, that seems to be an extra safety measure rather than the essence of the idea. Going back to my original example of parsing a Username and verifying that it doesn't contain any illegal characters, how does a parser convert a string into a more direct representation of a username without using a string internally? Or if you're parsing an uint8 into a type that logically must be between 1 and 100, what's the internal type that you parse it into that isn't a uint8? |
|
IP address would be about the minimum amount of structure. Something else would be like processing API requests. You can take the incoming JSON and fully parse it as much as possible, rather than just validate it is as expected (for example drop unknown fields)