Dynamic or static typing?

Dynamic or static typing?

When it comes to dynamic and static typing there are big discussions and many opinions all around. I’ve collected following thoughts about this problem. Each one of it is questionable because programming is not black & white world. This is what is said in general (the truth is probably somewhere in-between):

Static typing:

  • it is recommended for large projcets with shared code bases
  • it is expected lower maintenance cost
  • usually enforces OOP, classical inheritance and interfaces
  • it is IDE dependent
  • good refactoring tools
  • code is more verbose
  • project contain much more files and lines of code
  • there are more levels of indirections when reading code
  • many data container classes and translation logic between them

Dynamic typing:

  • recommended for small and middle size projects
  • faster development
  • shorter, more elegant and expressive code
  • usually don’t need IDE
  • enforces functional and flat application design
  • types are checked at runtime
  • it is sometimes hard to find what the object structure is
  • error prone when not practicing unit testing
  • harder refactoring

In reality it also depends on other aspects such as skills, preference of development team or project requirements itself. The truth is that big and reliable software was built in both languages with strict type checker like Java, C#, C++ as well as in dynamic languages like Python, JavaScript or Groovy.

What really matters is if you test your code. Type checker is the first line of tests which will fail fast in case of typos or even serious type problems. On the other hand the effort spent in satisfying type checker and working in more verbose environment can be invested in better unit tests. In any case you should test your units and business logic, if you don’t even type checker won’t save your application.

Choosing one or the other approach is hard and often opinionated decision. There are strong advocates of both approaches however there is no clear winner.

Add a comment

*Please complete all fields correctly

Related Blogs

Posted by Martin Bielik | September 9, 2016
Testing side effects using redux saga
In this post I'll try to show you how convenient it is to test side effects using redux saga. To read this post you should know something about generators and redux-saga library. Here...
Posted by Martin Bielik | August 9, 2016
Testing React Applications with Karma, Jest or Mocha
Nowadays in the ever changing "world of JavaScript and React" there are many libraries which could be used to test React components. It could be hard especially for newcomers to find...
Posted by Martin Bielik | December 23, 2015
Tech talks: Concurrent tasks in Node.js
Nodeschool workshops have finally started in Bratislava (hosted by Progressbar). At the first meet-up we set up node environment and went through several workshoppers from the nodeschool site. There were people from...