The debate on the benefits and limitations of type systems is ongoing and there are legitimate points on both side. In this article, I will explore a few benefits I've personally experienced from using type systems.
Refactoring - I'm always aiming to reduce complexity. It is a popular notion that it takes work express an idea concisely. So, when you're paying off technical debt, a type system can help tremendously. When the workings of some functionality or process is spread across many different files, libraries, and/or components, type systems are a boon.
Composition - writing unit tests is great practice. A type system can go further and test how different units compose and come together. In the example below, all the functions are working fine; the problem lies in our use of them. We are accessing a property that doesn't exist--thankfully, this well typed
pipelinefunction caught this right away.
Runtime errors - it's better to have compile-time errors than runtime errors--especially if they're hard to catch!Babak@babakness@getify Runtime errors are much more expensive than compile time errors.04:09 AM - 07 Mar 2019
Collaborating - between colleagues, teammates, library authors, or yourself from the past or in the future, I've found that a type system helps me understand how data is transformed, how events are handled, and what parameters a component expects.
Yet, type systems are not necessarily the right solution all the time. One common scenario I find myself leaving them out is when I'm teaching. Other times include when I'm prototyping or kicking the tires on some new library. It makes sense to just sketch something out and see what happens.
That said, the way I see it, for projects that can grow in complexity, there are more benefits to using them than not. The debate will go on, and there are other valid points against them.
To paraphrase Kierkegaard, use a type system or don't use a type system; you may still regret it. Hopefully I've given four good reasons on why you should use them, without regret! 😉