Making Invalid States Unrepresentable
I came across Andrew Watson’s article entitled “Make Invalid States Unrepresentable” the other day, and I found that I very much agreed with its premise and that it made some good points.
Strange as it might sound, being able to make invalid states unrepresentable is one of my favorite parts of programming, as I like crafting clear and rock-solid code (not that I’m not still learning how to best to so, of course), and I think it’s largely why I prefer working statically typed languages as well. It’s just fun.
I also think it’s one of the factors that attracts me to functional programming languages and styles as well. Using smaller record(-like) types is safer and improves clarity, elucidating the story that the code tells and improving the developer experience.