Dynamic Typing != Weak Typing

In a statically typed language, we specify the types of variables, references, and so on at compile time—and many compilers insist that we do. Take C/C++ for example. We have to specify the variable type as a primitive type such as int or double, or a specific class type. However, what if we cast the variable to a wrong type? Will the compiler stop us? No. What’s the fate of the program when we run? It depends. If we’re lucky, the program will crash. If not, it may wait until that important demo to crash or misbehave. Depending on how the memory is laid out, whether our call is polymorphic, and how the v-table (some languages like C++ maintain a method dispatch table with addresses of polymorphic methods—see Margaret ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.