Static vs Dynamic typing

So what is a datatype – in simple terms it’s the type of data. Lol! Okay but seriously, if I ask you what type is 10, you would say a number. And what type of number, you would say a decimal.

That is all there is to it. However it computer language, 10 is a value of type int. So the datatype of 10 is int or integer. Glad we got that out of the way.

Now there are two types of languages. One which tells you okay, you give me the value and I will figure out its type. This is weakly typed. You might have seen this –

var x = 10;

The language automatically understands what type of value is 10. And the other is strongly typed. Yup you guessed it –

int x = 10;

So why are there two types? Can’t all be just weakly typed. Well, with strongly typed you have more control over things going around in your code. Whenever you assign a different value to a strongly typed language it will complain that the type is not correct, hence preventing you from making mistakes. Whereas weakly typed variables allow you to assign any values. Am sure you don’t want this to happen.

x = "Ten";

C, C++, Java etc are strongly typed languages. Whereas Python, PHP etc are weakly typed languages.

But then what is static vs dynamic. In static typing the compiler figures out the type during compilation. So while you write you will start getting its properties or any functions that can be called on it (the intellisense magic). Whereas in dynamic typing the compiler refers to the type at runtime. This means if some property doesn’t exist on that variable it will throw an error during runtime.



Categories: What is

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: