Typing, Strong vs Weak, Static vs Dynamic
I thought Python was a weakly typed programming language because we didn’t need to define the variable type.
Let’s define Type Systems!
The type system is a set of rules governing the allocation of memory, operations allowed, etc. Programming language can be -
- Statically typed vs Dynamically typed
- Strongly typed vs weakly typed
STATICALLY TYPED languages are those where the programmer defines the type of variable, such as in C\C++.
int x = 0
My understanding of statically typed language is wrong because in Go, someone can define variables as
x := 0
As per my understanding, this should NOT be statically typed, but Go is a statically typed language. The correct interpretation of statically typed language is that the variable type is known at compile time.
This definition of static typing makes the definition of dynamic typing obvious, which is when the type is known as run-time, which is the case in python and javascript.
What about strong typing? These are the rules governing operations for a type. In Python, one cannot add an int with a string; hence, Python is strongly typed, while in Javascript, one can go crazy, which makes it weakly typed.
That’s all for now. Have fun!!
PS: The article is an extremely watered-down version of Typing. Type Systems have a chapter on their own in any book related to program analysis or compilers.