Type Systems

Frequently I read debates over static versus dynamic typing. Even though I am a programmer, this is Greek to me. So I decided to read up a little bit on them. I also recently read a blog entry that made me want to get intelligent, or at least proficient in this area. Static and dynamic typing refers to two classifications of type systems. A type is best understood by developers through an example. Integer, float, and string are all examples of types. Now let’s get more into type systems.

There are a number of ways to classify type systems. One of the most common is static versus dynamic. With static typing, the type checks occur during code compilation. Examples of languages with static typing are C++ and Java. The idea is that you can catch errors earlier during the compile. Also, the stereotype is that programs of statically typed languages execute faster.

Dynamic typing delays type checking until run time. This is also referred to as late binding. Examples of languages with dynamic typing are Perl and Ruby. In general, dynamic typing is more flexible. You also usually have less code to write. However the drawback is that the result executes more slowly. You also spend more time testing for bugs.

A blog entry by Chris Smith says that strong and weak have no meaning with regard to type systems. Or to put it a little less bluntly, strong and weak can mean many things with respect to typing. Even the word type means different things in the systems. There is also overlap between strong and weak typing. Chris states that all languages inherently have some dynamic typing features. Chris does not buy into the stereotypes about the features of strong and weak typing systems.

Controversy aside, Chris has a lot to say about type systems. He explained that type inference means the compiler decides the types from source code without the need of explicit type declarations. Examples of type inference style languages are Haskell and C#. Chris does concede that static typing does have advantages such as better performance, documentation, and correctness. He makes some analogies for the two classifications. In static typing, a type is equivalent to a variable. However in dynamic typing, a type is equivalent to a value.

I have to confess. Even after boning up on type systems with some research, I had to concentrate to try to follow Chris Smith’s blog entry. Much more study is required in this area. I would like to at least get to the point where I could answer simple interview questions such as “Tell me the difference between strong and weak typing”.