Comparison of Type Systems

12
Tamer Mohammed Abdul-Radi Backend Software Engineer at Cloud9ers Classifications of Type Systems What is the difference between the type system in Java and in Python ? tamerradi tamer_radi

description

How to classify the type system of programming langugaes, what is the difference between typesystems of Java, Javascript and Python ? What is the difference between Strong typed languages and statically typed languages ?

Transcript of Comparison of Type Systems

Page 1: 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

Page 2: Comparison of Type Systems

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

How strictly types are distinguished?

Answer is one of two● Weakly typed language● Strongly typed language

Page 4: Comparison of Type Systems

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

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

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

When type information is acquired?

Answer is one of two1. Statically typed language2. Dynamically typed language

Page 8: Comparison of Type Systems

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

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

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

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

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