The Unreasonable Effectiveness of Dynamic Typing for Practical Programs
&gt; This first slide is from a research paper where the researcher wrote his own language and make both a statically typed and dynamically typed version then got a bunch of people to solve programming problems in it. The results were that the people using the dynamic version of the language got stuff done much quicker.<p>Does this first plot control for notions of quality and extensibility of the different solutions? A faster-to-develop but sloppier solution in a dynamic language which requires more painful investment to refactor for future use cases should not necessarily be viewed as better. If you are only saving short term time at the expense of much more long-term time, then whether it is a net win for you depends on your discount function.<p>&gt; What was most interesting was that he tracked how much time was spent debugging type errors. In other words errors that the statically typed language would have caught. What he found was it took less time to find those errors than it did to write the type safe code in the first place.<p>For which developers, and with what level of experience with static typing? This was true for me 3 months after I started learning Haskell. Now I have &gt; 8 years of Python experience and less than 2 years experience with Haskell and the type system demonstrably speeds me up. Way, way faster to use Haskell&#x27;s type system first than to use Python&#x27;s type system and trace backs to debug type errors later. (I still like and use Python a lot -- just sayin.)<p>&gt; The guy giving the talk, Robert Smallshire, did his own research where he scanned github, 1.7 million repos, 3.6 million issue to get some data. What he found was that there were very few type error based issues for dynamic languages.<p>&gt; So for example take python. Out of 670,000 issues only 3 percent were type errors (errors a static typed language would have caught)<p>This strikes me as one of the most problematic parts of the post. To me this just seems to be evidence that in Python, at least, TypeError is more common when you are using something interactively, and you can resolve the issue for yourself (because it generally directly means <i>you</i> are using it wrong, and it&#x27;s <i>not</i> the library&#x27;s fault).<p>This also resonates with my experience with Pandas on GitHub. Early on there was a lot of TypeError stuff with index-related issues, but once the bulk of that work became mature, index errors were then a signal of a novice user who needed to change the user code, and not at all an indication of a library problem worthy of opening a GitHub issue.<p>It seems totally reasonable to me to hypothesize that the types of problems worthy of becoming GitHub issues are not usually TypeError. But TypeError might still be a huge proportion of all of the errors encountered out in the wild.<p>Further, there&#x27;s also some selection effects here for users who actually post things to GitHub. When I worked in quant finance, and everything was in Python, it was an hourly occurrence for hugely important parts of the system to hit type errors, and they were all incredibly painful to fix in the legacy code. This was just accepted as a way of life, and because the invest staff weren&#x27;t incentivized to care much about code, they usually just hacked their own work arounds, and would never have dreamt of actually opening a GitHub issue about type errors (that would be way too slow of a dev cycle for them, which is why the state of the code was so poor in the first place!)<p>&gt; His point there is that all that static boilerplate you write to make a statically typed language happy, all of it is only catching 2% of your bugs.<p>This is absolutely false and not a valid generalization of the presented data. For one, a major claim of static typing proponents is that by writing with static typing, it eliminates bugs from ever being introduced, and allows you to use a compiler workflow to verifiably remove entire classes of bugs. When you run some bit of Python and it does not produce a TypeError -- that doesn&#x27;t mean the code is free of errors. It might just mean you got lucky that the data or the user selections or whatever didn&#x27;t happen to hit the TypeError corner case. With a static language, you <i>know</i> that certain classes of errors are not even possible -- not just that they didn&#x27;t happen to occur this one time, but that they <i>cannot</i> occur. This is <i>very</i> different.<p>Further, another claim of static typing proponents is that the <i>design process</i> of code with static also leads to fewer bugs because the mandate for static types forces you to clarify befuddled design ideas before the program will work. The benefit of this is murkier, for sure, but it&#x27;s still something that can&#x27;t be addressed by this particular data.<p>&gt; Some other study compared reliability across languages and found no significant differences. In other words neither static nor dynamic languages did better at reliability.<p>It&#x27;s interesting to me that that chart doesn&#x27;t include any functional languages. Let&#x27;s try it again with a pure functional language and see, and then also compare, say, Clojure with Haskell. If it keeps on robustly bearing out the same trend, then I might start to question my current beliefs on defect rates in dynamic, imperative languages.<p>&gt; Part of that was reflected in size of code. Dynamic languages need less code.<p>This again is relative to the ability of a developer and also relative to different types of tasks. However, it&#x27;s not really fair to compare languages like C, where brevity of syntax was not too big of a language design priority, with a language like Python, where brevity of syntax is sometimes militant (just try talking with &quot;Pythonistas&quot; on Stack Overflow about why one-liner-ness is really not that useful). And also, at least part of the result is fixed for you: static typing at the very least requires the extra type annotations -- although here again you could try against something like Haskell where you have very powerful type inference. I would be extremely surprised if, for equivalently experienced developers, Haskell programs were not consistently shorter than Python programs.<p>&gt; He points out for example when he’s in python he misses the auto completion and yet he’s still more productive in python than C#<p>Try Jedi in emacs (or whatever the equivalent must be in vim). Although, I for one hate IDEs (get off my lawn) and I also hate autocompletion and editor utilities that jump to function or class definitions. I&#x27;ve never noticed a significant speed up from these, except possibly when I am merely reading code from a large codebase that is brand new to me. But I have often experienced huge slowdowns from the features getting in my way.<p>&gt; Another point he made is that writing static types is often gross and unmaintainable whereas writing unit tests not.<p>See Haskell. Also, writing unit tests can be a nightmare in OO and imperative settings, where you need some inscrutable cascade of mocked architecture to be able to test things. This is where something like Haskell&#x27;s QuickCheck can make life a lot easier. I&#x27;m sure you could cook up something like that in Python too. But I strongly believe that writing unit tests in Python is way uglier and more frustrating than writing type annotations in Haskell.