Type Systems
In this post you will learn what is a type system and the difference between static and dynamic type systems.
A type system assigns types to programming constructs. By programming constructs we mean functions, expressions, statements, variables, etc. The main function of the type system is to remove bugs in software, through a phase known as type checking, where the compiler assigns types to constructs and builds a sound mathematical model.
Sound means that the type system guarantees that your program behaves properly, always rejecting programs that are illegal according to the mathematical rules.
Type checking can happen at compile time or at runtime; when the type checking happens at compile time, we have a statically typed language. If the type checking happens at runtime, we have a dynamically typed language. For all purposes in this book, we consider only static and dynamic type systems. (In the research literature, there are languages that mix static and dynamic type systems but these are outside the scope of the book)
For example, Java is a statically typed language and would reject the program below, at compile time, if you call the method readingString with an argument of type int, e.g. reader.readingString(34); this is because the method expects an argument with a String type, not an argument with type int.
On the other side, we have dynamic languages such as Python. Most dynamic languages use duck typing. From the pragmatic point of view, duck typing means that we do not rely on types to specify whether the methods of an object exists: you call methods on objects as if they exist and, at runtime, if they do, great, if they don’t, the program throws an error. You can look at it from this other point of view: you are telling the object the behaviour that it should implement, whether it does or not is another story that you need to ensure yourself. Going back to the previous example, now written in Python:
If you have an instance of a Reader class, reader, you can potentially call reader.readingString("Test") and return a singleton list with the string you passed. However, you could also call reader.readingString(True), and the program will throw an error at runtime -- True does not have a method called toList().
The following table shows the main and most pragmatic differences between static and dynamic languages.

Originally published at http://www.programmingfightclub.com/grasp-principles/type-systems/
Please help spread the word. Thanks.
