"Parse, don't Validate" through the years with C++
Posted by dwrodri@reddit | programming | View on Reddit | 5 comments
Posted by dwrodri@reddit | programming | View on Reddit | 5 comments
elperroborrachotoo@reddit
Nice ride through C++ idioms. I wanted to complain that "you've changed a lot of things between versions", but I guess that's C++ and that's what you actually wanted to demonstrate, rather than something about PdV in particular.
My main gripe with PdV is the namimg. There's rarely some "real" parsing going on, and if, the parsing is not the core thing.
(That milk is spilled now, but hey, one can still complain.)
I'd express that as "use total types", i.e. types that can represent only valid values. "IsValid" is implied by the type (and becomes a function only for tests), and constructing an object of that type obviously requires validation and rejection.
lelanthran@reddit
I'm not sure what this blog post adds to the original idea by focusing on the implementation and not the interfaces.
My own spin on this was to show that a) it could be done, b) how to do it, and c) the numerous advantages.
With C++ we (already should) know that it could be done and we know how to do it (this is what the post covers).
C++ definitely has some nice advanced features for parsing and not validating, which I thought would be shown in this post.
dwrodri@reddit (OP)
Two things:
I often wonder whether writing blogs is worthwhile, because I generally concede that most of my ideas aren’t very original. I think there are many things many C++ programmers “should” know, but it changes, and new C++ programmers are minted every year! You need to talk to today’s 10,000.
Secondly, I’m a little confused what you mean by “interface” in this context. Perhaps you mean using a specific
Userclass with a Birthdate, where perhaps we’re reading it from a DB record and eventually write a derived result to a separate output (where isn’t as important as showing how the type gets moved around).I’ll check your account for your own elaboration on the subject. Thanks for the feedback!
lelanthran@reddit
I mean that I would have elided the body of the functions and just left the publicly visible fields/members. That's enough to show why you'd want to parse and not validate.
It gets reposted here on a semi-regular basis, but here's the link anyway: https://www.lelanthran.com/chap13/content.html
Alternative-Toe-5739@reddit
Keep it 55th street on HOOD. Big triple O General 55th street neighbourhood cryp on hood