0% found this document useful (0 votes)
59 views

Book of Good Explanations: 1. Static/Dynamic Vs Strong/Weak Typing

1. In statically typed languages like Java, the type is associated with the variable rather than the value, so once a variable is set to a type it cannot be changed. In dynamically typed languages like Python, the type is associated with the value rather than the variable, so the type of a variable can change. 2. Strongly typed languages like Python will throw an error if an implicit type conversion is needed, while weakly typed languages like PHP will implicitly cast one type to another. 3. Statically typed languages allow type checking at compile time, while dynamically typed languages check types at run time since they are usually interpreted rather than compiled.

Uploaded by

der.domme4284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Book of Good Explanations: 1. Static/Dynamic Vs Strong/Weak Typing

1. In statically typed languages like Java, the type is associated with the variable rather than the value, so once a variable is set to a type it cannot be changed. In dynamically typed languages like Python, the type is associated with the value rather than the variable, so the type of a variable can change. 2. Strongly typed languages like Python will throw an error if an implicit type conversion is needed, while weakly typed languages like PHP will implicitly cast one type to another. 3. Statically typed languages allow type checking at compile time, while dynamically typed languages check types at run time since they are usually interpreted rather than compiled.

Uploaded by

der.domme4284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Book of good explanations

1. Static/Dynamic vs Strong/Weak typing

Simply put it this way: in a statically typed language the type is static, meaning once you
set a variable to a type, you CANNOT change it. That is because typing is associated
with the variable rather than the value it refers to.
For example in Java:

String str = "Hello"; //statically typed as string


str = 5; //would throw an error since java is statically typed
Whereas in a dynamically typed language the type is dynamic, meaning after you set a
variable to a type, you CAN change it. That is because typing is associated with the
value rather than the variable.
For example in Python:

str = "Hello" # it is a string


str = 5 # now it is an integer; perfectly OK
On the other hand, the strong/weak typing in a language is related to implicit type
conversions (partly taken from @Dario's answer):
For example in Python:

str = 5 + "hello"
# would throw an error since it does not want to cast one type to the other
implicitly.
whereas in PHP:

$str = 5 + "hello"; // equals 5 because "hello" is implicitly casted to 0


// PHP is weakly typed, thus is a very forgiving language.
Static typing allows for checking type correctness at compile time. Statically typed
languages are usually compiled, and dynamically typed languages are interpreted.
Therefore, dynamicly typed languages can check typing at run time.

You might also like