Q: I often heard the claim that dynamically typed languages are more productive than statically typed languages. What are the reasons for this claim?"
This has historical reasons. If you go back a few decades, dynamic languages were indisputably vastly more productive than static languages (while also significantly slower). Perl is clearly much more productive than C if you know both and the task at hand allows either. But over time languages have borrowed a lot from each other, and newer languages are narrowing the gap (both in productivity and performance).
Here are some points to consider:
Garbage collection: Garbage collection is a huge productivity boost. I believe Java was the first mainstream static language with GC. Before this, static basically meant manual memory management. (Note: Here and in the following I'm only considering mainstream languages. Lots of experimental and niche languages exists which will provide counterexamples to any point I make.)
Memory safety: It is a productivity improvement that you don't have to worry about shooting yourself in the foot. Before "managed" static languages like Java, static typically meant direct memory access. Debugging is also a part of productivity, and unsafe memory access can lead to really obscure bugs.
Cumbersome type systems. Before the introduction of parameterized types (like templates or generics) in static languages, the limitations of the static types systems were often a burden. For example in Java you had to explicitly downcast every time you picked an item from a collection. So you got the syntactic overhead of a cast and no type safety. Considering how ubiquitous collections are in programming, this was a major drawback.
Having to declare the type of everything is a lot of redundant typing, but with modern type inference, this can be reduced significantly.
Big standard library. Python was famously advertised as "batteries included" because of the large standard library. This in comparison with C which have a very minimalist standard library. But with platforms like Java and .net, a vast standard library is becoming standard, and newer languages like Scala and F# are inheriting this "for free".
First class data structures. Dynamic languages like Perl and Python have built-in first-class data structures like lists and maps with convenient syntactic shortcuts for common operations. Compared to this, C have no built-in collections except fixed-size arrays.
Closures and lambda syntax - dynamic languages typically have had this from the beginning, but static languages have adopted this, most recently Java.
REPL the ability to quickly test code snippets interactively is a huge boon. But though IDE tools, like the "immediate" window in Visual Studio, static languages can emulated this to some extent.
Advanced tooling - in addition to the above points where static languages are getting closer to the convenience of dynamic languages, modern editors are taking advantage of static analysis in a way that dynamic languages have a hard time matching. For example editors can provide safe automatic refactorings, something that is strictly speaking impossible in a dynamic language.
Bottom line: Historically it was true, but today the answer is less clear cut.
Q: So: what is there to say for productivity with dynamic typing that really is an advantage of the type model itself?
It is somewhat hard to separate the dynamic typing model from dynamic languages, but as an example C# have adopted more an more dynamic features over time, even though it as its core is a static language. This is really a proof of benefit of the dynamic type model. Examples:
Reflection
Reflection is fundamentally a dynamic typing feature. You inspect object types at runtime rater than compile time. When it was introduced it was kind of frowned upon, but in C# the use of reflection gets more and more ubiquitous, for example ASP.Net MVC uses reflection heavily.
Attributes
Attributes are an example of dynamic typing. You can add arbitrary attributes to a class at compile time, and then you inspect at runtime (through reflection) and manipulate objects based on it. Something like MEP is basically an extension framework based on a dynamic type model.
Linq to SQL, EF mv.
The various Linq transformers inspect queries as runtime objects and generate sql on the fly. It doesn't get more dynamic than inspecting code at runtime. CodeDom is the other side of the coin, where code can be generated at runtime
Roslyn
Roslyn basically implements eval
, which was once considered the defining feature of a truly dynamic language.
Dynamic
The dynamic
-type is the most explicitly dynamic feature in C#, and is advertised at making interaction with external objects and languages simpler and more productive. But it is also used in Asp.net MVC for convenience.
The benefit of all the above features shows that the dynamic model have definite advantages even in a static language with parameterized types, structural types and type inference.