Prefer Parsing Over Validating: Let The Compiler Help You Remove Edge Cases
In this blog post, I’ll discuss a technique that I’ve used to create expressive APIs that are more robust with the help of the compiler. I’m going to demonstrate a simple example of this technique in Java but anything you are about to read can be applied to any other statically typed language. Let’s start by quickly defining “parsing” and “validating”. In my mind, validation is about analyzing input and reporting if it adheres to a certain set of validation rules:...