Comparison of Type Systems
-
Upload
tamer-radi -
Category
Education
-
view
2.073 -
download
3
description
Transcript of Comparison of Type Systems
Tamer Mohammed Abdul-RadiBackend Software Engineer at Cloud9ers
Classifications of Type Systems
What is the difference between the type system in Java and in Python ?
tamerradi
tamer_radi
Classifications of type systems
We can classify any type system by answering two questions1. How strictly types are distinguished?2. When type information is acquired?
How strictly types are distinguished?
Answer is one of two● Weakly typed language● Strongly typed language
Weakly typed languages
● A language in which types may be ignored.● In JavaScript:
"12" - 2 == 10 (without doing any explicit conversion)
● Javascript is weakly typed
Strongly typed languages
● A language in which types are always enforced.
● If you have an integer, you can't treat it like a string without explicitly converting it.
● Java and Python are strongly typed.
Classifications of type systems
We can classify any type system by answering two questions1. How strictly types are distinguished?2. When type information is acquired?
When type information is acquired?
Answer is one of two1. Statically typed language2. Dynamically typed language
Statically Typed Language
● A language in which types are fixed at compile time.
● Values have types, and variables too! (must match the type of values that holds)
● Java and C are statically typed languages.
Dynamically types langauges
● A language in which types are discovered at execution time.
● Values have types, but variables do not!● JavaScript and Python are dynamically
typed, because they figure out what type a variable is when you first assign it a value.
Conclusion
● Java is "Strongly typed" and "Statically typed"
○ You can't subtract "12" from 2○ Variables have types, you have to define them in
compile time.
Conclusion
● JS is "Weakly typed" and "Dynamically typed"
○ You can subtract "12" from 2○ Variables doesn't have types
Conclusion
● Python is "Strongly typed" and "Dynamically typed"
○ You can't subtract "12" from 2○ Variables doesn't have types (or weakly typed, and
can be changed later)○ Python uses Duck typing, which is an extreme style
of dynamic typing○ We will talk about Duck typing later