
On Apr 12, 2014, at 11:14, James Nelson <retrobanana.jn@gmail.com> wrote:
In retrospect, statically typed variables does contradict Python's duck typing: it shouldn't matter if it's a float or an integer,
Or, more importantly, some type you never thought of--maybe it's a numpy array of int16s...
as long as you multiply or divide, you're fine, and if you need a specific type, you just check with type().
Actually, even if you need a specific type, you usually want to check with isinstance. Only use type if you explicitly don't want to handle subclasses, ADT registration, etc., which is very rare. Anyway, while you presented this as an afterthought, duck typing is the whole point of dynamic languages like Python. You get the flexibility of a powerful polymorphic type system (like the ones in ML or Haskell, or to a lesser extent C++), while only having to ever think about (and write) simple types (like the ones in pre-generics Java or ActionScript). Of course the cost is that you don't get compile-time type checking. But for many programs, that type checking is nearly useless (at least the Java kind; the Haskell kind is more useful). Anyway, Python has had annotations for years now, and one of the reasons they were added was so someone could write a type-checking linter that statically checked optionally-annotated function and parameter types, and nobody is using it for that. Which implies that nobody is missing it too badly.