Live data from Hacker News

Parse, Don't Validate (2019)

lexi-lambda.github.io

171–175 of 175 posts

Re: Parse, Don't Validate (2019)

#171

It seems modern statically-typed and even dynamically-typed languages all adopted this idea, except Go, where they decided zero values represent valid states always (or mostly). A sincere question to Go programmers – what's your take on "Parse, Don't Validate"?

Go was written for programmers with little to no Computer Science knowledge, a fair bit of C/C++ experience, and zero tolerance for learning abstractions that take more than 30 seconds to explain. If you have opinions about type systems, you are not the target demographic for Go.

Re: Parse, Don't Validate (2019)

#172
post #100

Earlier quoted context omitted.

At first I had a negative reaction to that comment and wanted to snap back something along the lines of "that's horrible" as well, but after thinking for a while, I decided that if I have anything to contribute to the discussion, I have to kinda sorta agree with you, and even defend you. I mean, of course having a string, when you mean "email" or "date" is only slightly better than having a pointer, when you mean a s…

> So, when you model data "correctly" and turn "2026-02-10 12:00" (or better yet, "10/02/2026 12:00") into a "correct" DateTime object, you are making a hell lot of assumptions, and some of them, I assure you, are wrong. I think that's the benefit of strong typing: when you find an assumption is wrong, you fix it in a single place (in this example, the DateTime object). If your datetime values are stored as strings e…

First of all, you are imagining some strawman situation, where indeed that datetime is encoded-decoded all across the codebase. Don't keeping your code DRY is an entirely different problem, which doesn't need to happen with this approach any more than if you use a DateTime. I don't mean it theoretically, I mean, really, I was working with codebases, where this approach was taken, and all was fine. You still would have 1 class that works with DTs, it's just that it mostly contains functions of type str → str, and for the rest of the system it's a MySQL-format datetime (i.e. a string). And the point is that your system doesn't try to make any assumptions about that string unless really needed, so you always preserve the original string (which may be a completely invalid gibberish for all you care), and while some auxillary processes might break, you never lose or destroy the original data that you received (usually from some very important 3rd party system, that doesn't care about us, so you cannot really break on input: you must do your best to guess what that input means, and drop whatever you couldn't process yourself into some queue for human processing).

And also, second, this is more specific to this particular example, but when we say "DateTime object" we usually mean "your programming language stdlib DateTime object". Or at least "some popular library DateTime object". Not your "home-baked DateTime object". And I've yet to see a language where this object makes only correct assumptions about real-life datetimes (even only as far, as my own current knowledge about datetime goes, which almost certainly still isn't complete!). And you'd think datetimes are trivial compared to the rest of objects in our systems. I mean, seriously, it's annoying, but I have to make working software somehow, despite the backbone of all of our software being just shit, and not relying on this shit more than I need to is a good rule to follow. Sure, I totally can use whatever broken DateTime objects when the correctness is not that important (they still work for like 99% of use-cases), but when correctness is important, I'd better rely on a string (maybe wrapped as NewType('SpecialDate', str)) that I know won't modify itself, than on stdlib DateTime object.

Re: Parse, Don't Validate (2019)

#174

Earlier quoted context omitted.

Obviously the pseudo code leaves to the imagination, but what benefits does this give you? Are you checking that it is 10-digits? Are you allowing for + symbols for the international codes?

You have functions void callNumber(string phoneNumber); void associatePhoneNumber(string phoneNumber, Person person); Person lookupPerson(string phoneNumber); Provider getProvider(string phoneNumber); I pass in "555;324+289G". Are you putting validation logic into all of those functions? You could have a validation function you write once and call in all of those functions, but why? Why not just parse the phone numbe…

Remember that the ancestor gave a pointless wrapper class plus the sarcastic remark "Huge pain."

Re: Parse, Don't Validate (2019)

#175
post #11

This is a great article, but people often trip over the title and draw unusual conclusions. The point of the article is about locality of validation logic in a system. Parsing in this context can be thought as consolidating the logic that makes all structure and validity determination about incoming data into one place in the program. This lets you then rely on the fact that you have valid data in a known structure i…

I disagree. I think the key insight is to carry the proof with you in the structure of the type you 'parse' into.

In order to carry the proof, you have to parse it early (otherwise you're not carrying it the whole time before parsing), so you you're both right.
Post reply on HN