Parse, don't validate. A classic that I keep coming back to. The core idea is very simple: instead of validating data and throwing away what you learned, parse it into a more precise type that preserves that knowledge. The rest of your code gets simpler because impossible states become unrepresentable.

Using this pattern well will remove a lot of „if" statements and error handling scattered around the codebase.

Recent articles