Dynamically Typed and Statically Typed languages
It's a tough debate
There is no shortage of programming languages — Python, Ruby, Java, C++ — you name it. The diagram above is a good way to categories them.
So how do these programming languages differ?
So what does this mean?
However, in a statically typed language such as C++, if we wanted the same result, we would have to write our code differently.
Notice that with a statically typed language, we have to specify in advance what type var a is going to be — an integer in this case.
Here, we explicitly declare the variables before using them. In a dynamically typed language, we are not bound to this constraint.
This is why we are able to use dynamically typed languages and assign anything to a variable and things don't break. You might get errors during run time while the user is browsing the website, but because our just in time compilation, we don't have to worry about this.
Now, this all sounds good. But it isn’t always ideal. It might cause problems as well.
Different people have different opinions as to whether Statically typed languages are best to use or dynamically typed languages. It's a tough debate.
The best way to think about this is to look at the pros and cons of each or at least where one shines over the other.
Pros of a Statically typed language
This above example demonstrates what a statically typed language could do. If a new developer came along and ran the sum function with anything other than a number, for example:
This will automatically error out before we put the code to the browser or in production. Something is evidently wrong here because the program expects a number and you are giving it a string.
In that sense, statically typed languages are self-documenting. You see right away the kind of parameter it expects and avoid making an error even if the function was named badly or if it was a complicated function.
2. Auto-completion in IDE’s. This is nice when you are developing. Because of the self-documenting nature of the language, it helps with auto-completion in IDE’s. You can download plugins that show you right away even before you run anything that for example — this should be a number.
3. Fewer bugs in production.
Fewer bugs will make it to production. If something fails at compile-time, we catch it early before we even send it to a browser.
Cons of a Statically typed language
- An added layer of complexity.
We have just made our code a little harder to read. We are just adding another layer of complexity and this can have a learning curve.
2. Why not just write better tests?
A lot of people get excited about statically typed languages and forget about good unit tests.
It’s easy to just assume that because you have static typing, you are not going to get any bugs. That simply isn't true.
3. Slower developing process.
This is because now you have added another step to the code creation process. Because while coding along, there is another check to see that you are not making any type-errors. This slows down the process and how fast you can create, run and ship code to production.
Statically typed languages usually prevent bugs and stop errors from happening. Dynamic typing allows you to be more flexible and write software faster.
Technology will save homo sapiens from extinction