Dynamic / Static Typing vs. Strong / Weak Typing

Here is a great article about Static vs. Dynamic typing and Strong vs. Weak typing.

But as to summarize it ; Dynamic typing languages are which variables’ type declarations are not mandatory and they will be generated on the fly, by their first use [PHP, Python]. While Static typing languages are the ones which variable declarations are mandatory before usage [Java, C].

/* C code */
static int num, sum;
num = 5;
sum = 10;
sum = sum + num;
/* PHP Code */
$sum = 10;
echo $sum;

On the other hand the difference between Strong and Weak typing is different; Strong typing is when a variable is declared as a specific type (no matter by Dynamic or Static typing) it is necessarily bound to that particular data type [Python, Java]. While in Weak typing variables are not of a specific data type ;  it does mean that variables are not “bound” to a specific data type [C,PHP] [1].

# Python code
>>> foo = "x"
>>> foo = foo + 2
Traceback (most recent call last):
File "", line 1, in ?
foo = foo + 2
TypeError: cannot concatenate 'str' and 'int' objects
/* PHP code */
$foo = "x";
$foo = $foo + 2; // not an error
echo $foo;

[1] Introduction to Static and Dynamic Typing

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