←back to thread

Parse, Don't Validate (2019)

(lexi-lambda.github.io)
389 points melse | 2 comments | | HN request time: 2.355s | source
Show context
bruce343434 ◴[] No.27640435[source]
This still sounds like validation but with extra steps. (or less?)
replies(3): >>27640629 #>>27640647 #>>27642145 #
plesiv ◴[] No.27640629[source]
The post is saying:

- don't drop the info gathered from checks while validating, but keep track of it

- if you do this, you'll effectively be parsing

- parsing is more powerful that validating

"Extra steps" would be keeping track of info gathered from checks.

replies(1): >>27641503 #
bruce343434 ◴[] No.27641503[source]
Right. My takeaway was "verify and validate once, then put it in a specially marked datastructure, or if your language allow it make the typesystem guarantee some conditions of the data, then work with that from there". Where does parsing come in the picture?
replies(3): >>27642118 #>>27642191 #>>27642202 #
justinpombrio ◴[] No.27642202[source]
You understand it. It's using the word "parse" metaphorically, to mean "validate, then put it in a specially marked data structure". For example, `parse_int :: string -> maybe int` is a parsing function, and it "validates that the string is an integer, then puts it in a specially marked data structure called int". However, the post uses the word "parse" not only for true parsing functions (that convert text into a data structure), but also for conversions from data structure to data structure.

I also find this a confusing use of the word "parse", and it's not explained in the post, and I think "parse, don't validate" is a poor slogan as a result. The traditional slogan is "make illegal states unrepresentable", though that's a bit narrower of a concept.

replies(1): >>27645030 #
1. b3morales ◴[] No.27645030[source]
I don't think this is the same as "make illegal states unrepresentable"; it's a corollary (or the converse maybe):

"Make assertions of legal states representable"

replies(1): >>27645852 #
2. joshuamorton ◴[] No.27645852[source]
They're sort of the same. If you have str and safestr, and safestr is known to confiorm to some invariant, the illegal state of a, say str where validate hasn't been called, isn't representable.