Picture of myself

Static vs. Dynamic typing

February the 11th in year 2015

I made a bit of research about the languages of today, and as it turns out they have something called type system. This type system has something called type checking. And it's the type checking I'll be talking about today.

There are two ways:

Static type checking
and
Dynamic type checking

There seems to be a battle out there in the programming community revolving around which one is best. I have travelled around the internet to find a definitive answer, but all I found was, that there is none. I could have ended just here, but than I would feel all my research would go to waist. I don't want that, so I'll try my best to describe each one of them to you.

Let’s start with Static Typing.

When working with these languages we usually don't type the programmes in a regular text editor. Well, you can, but why would you when you have something really cool called IDE! It stands for Integrated Development Environment. A short list of the most popular IDEs at the moment:

But why would one use this environments instead of a regular text editor? IDEs offer something really awesome. When you write the code it will automatically suggest all the methods you can call on this object. This is called "intelligent code completion", or as it is commonly known as IntelliSense, a term picked up from Visual Studio's name for it. And this is where we came to the main difference between the two.

When running static type language code, it will first go to the compiler and after he does his magic, which means translate it to some more basic language, that computer understands, it will then be sent to runtime and displayed on your screen. This means it will have fewer errors by the time it reaches runtime, as compiler will check it first. IDEs usually have the compiler already integrated in them, but it's important to know that they are not the same thing.

Static does have some drawbacks though. It's much harder to reuse code, and it takes longer to compile.

Famous languages representing static typing:

And now let's focus on what we at DBC are more familiar with. Dynamic Typing.

As we know we don't have IDEs when writing in Ruby, because it is a dynamic typing language, and we use normal text editor. There are plenty to choose from, and I'll mention just a few which seem to be popular with coders:

By now we already know that IDE is not the same as a text editor, as text editor doesn't compile, and it doesn't provide us with IntelliSense, but there is as tool for ruby that comes close to it. It's called RubyMine. It's not prefect but it brings the experience closer to the opposition. Just so you know, this is not the only tool like that for dynamic typing. What RubyMine provides for Ruby, Visual Studio provides for JavaScript.

With static typing this is easy, because IDE just asks the compiler what are the options. Why is it than so hard with dynamic typing? Where is the compiler? Does dynamic typing even need compiling? Of course it does! Computer can't read Ruby code directly! So if it needs compiling, when does it happen then? Here's the big difference again. It happens at runtime. This two processes are combined into one. That's why we get the error messages when we run the code, while if you'd try the IDE you'd get all the fancy display of the errors in messages and in the code.

We need to mention that despite not having ability of compiling pre runtime, dynamic typing is faster, has more reusable code, and programmer has more control, while the downside is that output is not guaranteed and you as a programmer have more responsibility.

At the end, I'll put down some of the most famous languages representing dynamic typing:

I hope I got things a bit clearer on the subject. If not, there's a whole internet worth of a pages on the subject. Good luck :-)

...by Marko Anton Potocnik