Skip to content
Tech News
← Back to articles

"Parse, don't validate" through the years with C++

read original get C Programming Book → more articles
Why This Matters

This article highlights the evolution of the 'Parse, don't validate' paradigm in C++ and its significance in improving code robustness by leveraging type systems for data validation. It emphasizes how this approach can simplify handling complex data inputs like dates, ultimately enhancing reliability and maintainability in software development.

Key Takeaways

Published April 17, 2026

Alexis King’s Parse, don’t validate had a huge impact on how I write code, particularly my stance toward Python type annotations in production. However, as someone who has written practically zero Haskell, the idea didn’t click for me until I started seeing other examples, like this one in Rust. This post explores how we can take this paradigm and apply it to a simple date-parsing problem in C++98, C++11, C++17, and finally C++23.

If you haven’t read the original essay, it is a great explainer for a genuinely tricky topic. Here’s my attempt at summarizing the key idea:

Use your language’s type system to parse unstructured inputs. A successful instantiation of that type should mean the data is valid, and you eliminate the need for validation control flow down the line.

I’ve revised this summary a few times and I still don’t love it. Likely a mix of skill issue and the fact that the idea is very hard to stuff into the small box of two sentences without relying on more jargon, which I am still using.

Timestamp and date parsing are notoriously riddled with edge cases. That being said, much like validating email addresses, it’s a perfect example of a problem where a programmer has to make a contextually optimal tradeoff between correctness and readability.

In this case, let’s imagine we’re building something that consumes unstructured data from a file, and we need to extract personally identifiable information. For the purposes of this post, I’ll be ingesting a raw string, raw_input , that needs to be used by the rest of the code.

Starting point

Let’s start with a dead simple implementation that is mostly apathetic to the idea of type-driven design.

See it in Compiler Explorer

... continue reading