Recently (read: today) I got quite confused in separating the concepts of Dynamic vs Static  and  Strong vs Weak typed languages.
So I took the time to figure it out for myself.
Later I thought It would be nice to just quickly (and shortly) write down the key differences between them.

Dynamically Typed vs Statically Typed

The main difference lies in how you define variables

Statically typed

A statically typed language is a language that requires the programmer to specify the type of a variable when writing code

//JAVA

String a = "It's me, Mario!;
Integer b = 3; //assumed using version with autoboxing

Dynamically typed

You guessed it, you don’t have to specify the type of the variable! A very important remark is that this does not imply that the language is weakly typed, i.e. : it doesn’t mean the languages doesn’t use types!


var a = "It's me, Mario!";
var b = 3;

Strongly Typed vs Weakly Typed

The main difference here lies in how variables are used by the language

Strongly typed

This means that the language has a sense of types. Meaning that it will complain if you try to append  or add an integer to a double.

In a very strongly typed language this would mean:

Strongly Statically typed


Double a = 2.0;
Integer b = 3;

a+b; //will give error

Double d = b; //will give error

Strongly Dynamically typed


var a = 2.0;
var b = 3;

a+b; //will give error

Weakly typed

This bascally means that you – as a programmer – mostly don’t have to worry about types when using variables

Weakly Statically typed


Double a = 2.0;
Integer b = 3;

a+b; //Most languages will return 6.0

Double d = b; // the integer will be casted to double for you

Weakly Dynamically typed


var a = 2.0;
var b = 3;

a+b; //mostly will give 6.0

One last note:

You might have noticed that I used “very strongly typed”earlier in this post. Meaning that there are gradations between them. For example: Java is a strongly typed languages but has some weakly typed properties like appending an integer to a double. Java will automatically cast the integer to a double. Another weakly typed property of Java pops up when you are trying to concatenate strings with arbitrary objects. Here java will automatically try to convert any non-string object to a string representation.

 
I’ll leave exploring the (dis)advantages of different type systems to yourself!

Advertisements