There hasn't been a lot of study on this topic* but what little there is shows that 3% of errors found can be mitigated with type systems, where they do not exist, fixing these classes of errors takes less time than it took to use the type system.
* https://www.infoq.com/presentations/dynamic-static-typing/
It seems to me like you're cherry picking evidence. Copy-pasting from a previous comment I made in another thread (https://news.ycombinator.com/item?id=19530274):
There is plenty of evidence showing that modern type systems reduce bugs considerably.
In Airbnb, they found out that 38% (!) of bugs could have been prevented by using TypeScript[1].
Another scientific study discovered that TypeScript and Flow could prevent about 15% of bugs in committed code [2]. And these aren't even measuring reduction of bugs in non-committed code!
Stripe is also writing their own type checker for Ruby and engineers have reported an increase in productivity[3].
[1]: https://news.ycombinator.com/item?id=19131272
[2]: https://blog.acolyer.org/2017/09/19/to-type-or-not-to-type-q....
Isn’t dynamic typing more or less a default state of not knowing anything at compile time about the values your data will take?
One could equally well ask “given that the boundaries of our systems are necessarily characterized by unpredictability, doesn’t it make sense to invest in more ways to isolate that unpredictability better (e.g. by use of static analysis)?”
Programs in such languages must be statically type checked --- by the coder.
Sometimes (usually?) those languages define the effects of type punning, so type mismatches are not necessarily errors. The programmer must know which are intentional (to be analyzed for correctness from a type-punning perspective) and which are bugs. This could come from comments or naming conventions.
Dynamic typing is a huge increment over this situation; what is surprising is how early the original Lisp people figured it out, while also inventing useful abstractions like symbols and whatnot.
Many interfaces have declared, enforced static types. I don't have to write any code to handle
SELECT birthdate FROM employees WHERE id = ?
returning "fish" because the database would never let it happen.Really? Okay, below is something that meets the definition of "arbitrary data". Can some static program process it and evoke its full meaning without the programmer having to develop an ad-hoc dynamic typing system?
(defun defset-expander (env macform name params newval setform)
(with-gensyms (getter setter args gpf-pairs gpr-pairs ext-pairs
pgens rgens egens all-pairs agens nvsym)
(let* ((ap (analyze-params params))
(exp-params (car ap))
(total-syms (cadr ap))
(fp (new fun-param-parser form macform syntax exp-params))
(fixpars (append fp.req fp.(opt-syms)))
(restpar (if (symbol-package fp.rest) fp.rest))
(extsyms [keep-if symbol-package
(diff total-syms (cons restpar fixpars))])
(xsetform ^^(alet ((,',nvsym ,,newval))
,,(expand ^(symacrolet ((,newval ',nvsym))
,setform)
env))))
^(defplace (,name . ,args) body
(,getter ,setter
(tree-bind ,params ,args
(let* ((,gpf-pairs (mapcar (op (fun list) (gensym)) (list ,*fixpars)))
(,gpr-pairs (if ',restpar
(if (consp ,restpar)
(mapcar (op (fun list) (gensym)) ,restpar)
(list (list (gensym) ,restpar)))))
(,ext-pairs (mapcar (op (fun list) (gensym)) (list ,*extsyms)))
(,pgens (mapcar (fun car) ,gpf-pairs))
(,rgens (mapcar (fun car) ,gpr-pairs))
(,egens (mapcar (fun car) ,ext-pairs))
(,all-pairs (append ,gpf-pairs ,gpr-pairs ,ext-pairs))
(,agens (collect-each ((a ,args))
(let ((p (pos a ,all-pairs (fun eq) (fun cadr))))
(if p
(car (del [,all-pairs p]))
a)))))
^(alet (,*,gpf-pairs ,*,gpr-pairs ,*,ext-pairs)
,(expand ^(symacrolet (,*(zip ',fixpars
(mapcar (ret ^',@1) ,pgens))
,*(zip ',extsyms
(mapcar (ret ^',@1) ,egens))
,*(if ,gpr-pairs
(if (consp ,restpar)
^((,',restpar ',,rgens))
^((,',restpar ',(car ,rgens))))))
(macrolet ((,,getter () ^(,',',name ,',*,agens))
(,,setter (,',newval)
,',xsetform))
,body))
,env)))))))))The requirement for dynamic typing can either come from the language, or it can be "Greenspunned", or some combination of the two.
For instance, in that data we can construct objects, and we can write expressions which interrogate an object's type.
Thus, that is an example of input data whose processing requires dynamic typing.
If the detailed requirements describing the inputs require dynamic typing, then the statically typed program has to whip up a facsimile of that dynamic typing. It's not an implementation detail; it shows up in visible, testable system behaviors.
And then, there you are, with the possibility of errors that are not caught at your compile time.
The debate that the article is addressing is the supposed difference of capabilities between programs written with static vs dynamic types, at runtime.
Here's one in C (less than 200 lines): https://carld.github.io/2017/06/20/lisp-in-less-than-200-lin...
Here's one in Haskell: https://www.defmacro.org/ramblings/lisp-in-haskell.html
You seem to have a set of rules that you think code in a statically typed language has to follow in addition to the type constraints in order for you to consider it sufficiently 'typed'.
If someone writes Haskell applications by defining an Expr type that is a sum of several dozen things, and then makes al their function arguments and return values of type Expr, is that still bona fide static typing?
To me the stronger argument is that the boundary between programs is dynamically typed (interpreted and checked at runtime). This is true in the statically typed example as well - the JSON is interpreted and checked at runtime, not at compile time. There's nothing your compiler can prove in advance about what's in the JSON that you'll receive at runtime.
If systems that extend beyond a single program require dynamic typing, doesn't it make sense to invest more in ways to do dynamic typing better?