Types provide a way to abstract data. 1 isn’t a collection of bytes in memory, it’s an Integer. Without types programmers would still be shuffling bits in memory. Types bundle up those bits and bytes and give a specific kind of collection of bytes a name. As with every system, no one can agree on a single way of working with types.
Languages using a static type system have all of the types checked when a program is compiled. This can make optimization easier for the compiler because types don’t need to be rechecked every time the program is run. C, Haskell, Java, Fortran and Go use static typing. However, most languages aren’t completely statically typed. Usually languages using static types have ways to get around the strict type requirements by using language features like unions and type casting.
Strong and Weak Typing
If a type system is strong type conversion must be done explicitly by the programmer. For example, if the string “5” and the integer 5 were to be added in C++ the result would be an error. The five would need to be casted to an integer to return 10.
A weakly typed language does that type conversion automatically. The previous example would be perfectly valid without explicit type casting in a weakly typed language.
Languages that use duck typing are more flexible in the way they handle objects. The type of an object doesn’t matter, only the implementation of the class. For example, if a duck typed language were to call
duck.speak(); all that would matter is that the duck object has a method called speak. The type of the duck object doesn’t matter, nor does the rest of the class.
The type system is a key factor of any programming language. It determines the entire structure of the language and how code is written with it. Next time you start a project, consider trying one with a different type system.