Comparison of Type Systems
-
Upload
tamer-radi -
Category
Education
-
view
2.073 -
download
3
description
Transcript of Comparison of Type Systems
![Page 1: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/1.jpg)
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
![Page 2: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/2.jpg)
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?
![Page 3: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/3.jpg)
How strictly types are distinguished?
Answer is one of two● Weakly typed language● Strongly typed language
![Page 4: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/4.jpg)
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
![Page 5: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/5.jpg)
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.
![Page 6: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/6.jpg)
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?
![Page 7: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/7.jpg)
When type information is acquired?
Answer is one of two1. Statically typed language2. Dynamically typed language
![Page 8: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/8.jpg)
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.
![Page 9: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/9.jpg)
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.
![Page 10: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/10.jpg)
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.
![Page 11: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/11.jpg)
Conclusion
● JS is "Weakly typed" and "Dynamically typed"
○ You can subtract "12" from 2○ Variables doesn't have types
![Page 12: Comparison of Type Systems](https://reader036.fdocuments.in/reader036/viewer/2022081813/54631b70b4af9f491c8b4912/html5/thumbnails/12.jpg)
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