The Unsound Playground: Java and Scala's Type Systems are Unsound
There have been some fantastic conversations on Hacker News about type systems. I&#x27;ve learned a lot about the different arguments for dynamic typing, versus strict typing, versus gradual typing. Java&#x27;s type system may or may not have represented new thinking when it was under development in the early 1990s, but it certainly seems a bit dated in the year 2016. The limits of the Java type system have been discussed both here on HackerNews and also elsewhere, many times.<p>For those who want to consider arguments against Java&#x27;s style of strict typing, 2 things I would recommend include &quot;Agility &amp; Robustness: Clojure spec, by Stuart Halloway&quot;:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VNTQ-M_uSo8" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VNTQ-M_uSo8</a><p>He offers a chart that shows the strengths and weaknesses of strict typing versus unit tests versus the run-time checks offered by Spec. It&#x27;s worth a look.<p>The discussions around gradual typing have been interesting, but to see how far the  limits of this can be pushed, I would suggest everyone check out the Qi&#x2F;Shen programming language:<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Qi_(programming_language)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Qi_(programming_language)</a><p>&quot;Qi makes use of the logical notation of sequent calculus to define types. This type notation, under Qi’s interpretation, is actually a Turing complete language in its own right. This notation allows Qi to assign extensible type systems to Common Lisp libraries and is thought of as an extremely powerful feature of the language.&quot;<p>This next quote is from someone who has spent a long time experimenting with different Lisps:<p>&quot;Qi (and its successor Shen) really push the limits of what we might call a Fluchtpunkt Lisp. I suspect it requires a categorization of its own. A few years ago I was looking for a Lisp to dive into and my searching uncovered two extremely interesting options: Clojure and Qi. I eventually went with Clojure, but in the intervening time I’ve managed to spend quality time with Qi and I love what I’ve seen so far. Qi’s confluence of features, including an optional type system (actually, its type system might be more accurately classified as “skinnable”), pattern matching, and an embedded logic engine based on Prolog, make it a very compelling choice indeed.&quot;<p><a href="http:&#x2F;&#x2F;blog.fogus.me&#x2F;2011&#x2F;05&#x2F;03&#x2F;the-german-school-of-lisp-2&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.fogus.me&#x2F;2011&#x2F;05&#x2F;03&#x2F;the-german-school-of-lisp-2&#x2F;</a><p>Mark Taver, who created Shen, posted a comment and then turned it into an essay here:<p>&quot;The underlined sentence is a compact summary of the reluctance that programmers often feel in migrating to statically typed languages – that they are losing something, a degree of freedom that the writer identifies as hampering creativity. Is this true? I will argue, to a degree – yes. A type checker for a functional language is in essence, an inference engine; that is to say, it is the machine embodiment of some formal system of proof. What we know, and have known since Godel&#x27;s incompleteness proof [9] [11], is that the human ability to recognise truth transcends our ability to capture it formally. In computing terms our ability to recognise something as correct predates and can transcend our attempt to formalise the logic of our program. Type checkers are not smarter than human programmers, they are simply faster and more reliable, and our willingness to be subjugated to them arises from a motivation to ensure our programs work. That said, not all type checkers are equal. The more rudimentary and limited our formal system, the more we may have to compromise on our natural coding impulses. A powerful type system and inference engine can mitigate the constraints placed on what Racketnoob terms our creativity. At the same time a sophisticated system makes more demands of the programmer in terms of understanding.
...That said, not all type checkers are equal. The more rudimentary and limited our formal system, the more we
may have to compromise on our natural coding impulses. A powerful type system and inference engine can
mitigate the constraints placed on what Racketnoob terms our creativity. At the same time a sophisticated
system makes more demands of the programmer in terms of understanding. The invitation of adding types was
thus taken up by myself, and the journey to making this program type secure in Shen emphasises the conclusion
in this paragraph&quot;<p><a href="http:&#x2F;&#x2F;www.shenlanguage.org&#x2F;library&#x2F;shenpaper.pdf" rel="nofollow">http:&#x2F;&#x2F;www.shenlanguage.org&#x2F;library&#x2F;shenpaper.pdf</a><p>I&#x27;m only quoting two favorites of mine, but of course I could post a hundred examples, all making a similar point. Java&#x27;s style of strict typing is both weak and incomplete, and yet overly rigid at the same time. It&#x27;s worth noting how many other strategies exist, that deliver more robustness, with greater flexibility.