Python/Typing

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Python is a strong, dynamic typed language.

  • Strong type means that every object knows exactly what type of object it is. Compare with C/C++ where you cannot tell what something is just by looking at its data in memory.
  • Dynamic type means that a variable or parameter can hold several different types of object. There is no way to limit what type a variable or parameter may hold.

Python 3.5 introduces an annotation system that Guido van Rossum explains in this YouTube video. This does not change how Python operates, but should make it easier to create tools that can analyze Python code for type errors.

Bob Ippolitto explains why this is important in What Python can Learn from Haskell. Basically, if you have static typing, you can do things like analyze your code for the most common types of bugs and improve execution speed with optimizations. If you don't, then that class of bug is hard to find and fix and you can't optimize the execution of the code. He points out that we need not be stupid about it (like Java) but can use techniques that Haskell uses to infer types as well as allow untyped parameters and variables.