Re:Why Python is Slow: Looking Under the Hood
by benjiweber on Saturday May 10, 2014 @05:24AM
(#7724916)
With inferred types you still know that callers must be passing something for which the operations performed are valid.
Many languages allow you to specify types even when they may be inferred to add clarity/preconditions. This is useful for modelling the domain as well as local reasoning. Perhaps the current implementation is valid for all integers, but in the domain context it only makes sense for the range 0-100.
If the compiler can infer the type locally then so can I. At least for reasonably well structured code.
Sometimes it computes a type and you have no idea what the type is about.
Also dynamic typing does not mean you don't know what a function receives or returns. Many dynamically typed languages are object oriented and use classes.
For example in Lisp I would write:
Then I know that the arguments are objects of class ship and submarine and it returns an collision-event.It's not statically typed, but the code is nicely readable and testable.