When (not) static typing matters

1 points by ankurdhama ↗ HN
I have been through a lot of articles about static vs dynamic typing. For me, static typing makes lot of sense when your language encourage you to create lots of new types (mostly classes/OO languages), because when you are working with such an API, static typing makes it clear about what a method takes and returns (and what those types represent) rather then going though documentation which hampers productivity. Static typing in practice is more about understanding a program/API rather than some academic "prove them correct" theory. Python, which encourage a lot of OO,class based programming including its so called frameworks is a not a good candidate for dynamic typing, coz every time you wana call an API you wonder what "object" it would take and what that object will have inside it including its base class etc etc.

On the other hand if you have a language like Clojure, with some basic types like vector,set,map, few other primitive types and "function type" (and if you don't create new types with deftype etc) then dynamic typing is preferable, because you know what all the function will be dealing with these types only and that info can be encoded as meta data on the functions itself (or comments if you don't have meta data facility in your language).

In end I would say if you create a lot of new types, then static typing is good and if you use some basic set of types (which are enough to represent any info/model) then dynamic typing is the way to do. So rather than discussing which is better, we should focus on which path we want to take while programming.

Let me know if this make sense for you guys.

Thanks.

1 comment

[ 6.1 ms ] story [ 16.2 ms ] thread
Well, regarding yout API example, Python 3 introduces function annotations which let you specify the types of the parameters and of the return value. These types are not checked by the interpreter, leaving this job to the programmer (or framework).

http://www.python.org/dev/peps/pep-3107/