sajad torkamani

All subjective / opinionated stuff here…

Let the compiler catch errors for you

The compiler catches property usages or method calls. Assuming an object is defined and using a property is a common runtime error (e.g., foo.bar where foo is null or undefined).

Assuming an object has a method that it doesn’t is also a common error (e.g., person.greet() where greet doesn’t exist). Let the compiler catch these errors for you so you avoid runtime errors in production.

Easier to read = less cognitive load

Types make your code easier to understand. You can look at a function and know (not guess) what type of arguments it expects and what type of values it returns. Less guessing = less cognitive load = more brain resource left to focus on domain problems instead of juggling types in your head.

Easier to refactor

Knowing that the compiler will catch type errors for you gives you the confidence to rename your variables, functions, classes, etc or to move files around. Without types, you’d need a good test suite to give you the confidence to do these refactorings on a whim.


Tagged: Misc