TDD and Dynamically-Typed/Interpreted Languages

One controversy in software development is the relative value of strong, static typing (as in compiled languages like Java) vs. dynamic typing (as seen in interpreted languages like JavaScript). No attempt will be made here to engage in this debate, but it is interesting to note the role of TDD in languages that are not statically typed.

For example, in Java, you could design a Square class that required a “height” and “width” to be passed in via its constructor. You could define that both height and width must be integers, and if code exists that attempts to create a Square by passing in something other than integers the code would fail to compile. No test would be created to guard against this. What might be a run-time error would be caught instead at compile time.

However, in JavaScript, there is no compiler. Code that attempted to create an instance of Square by passing in floating point numbers, or strings, or null would execute with perhaps unpredictable results.

TDD can help here for those who prefer dynamic typing. When such a restriction is deemed important extra tests can be added to ensure that critical parameters are of the correct type, moving the detection of potential errors from run-time to test-time.

This is Scott Bain. Visit us at

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.