Strong Static Typing vs Weak Dynamic Typing

Master programmers Carmack, Blow, Fowler, and Uncle Bob on strong static typing in contrast to weak dynamic typing.

Game developers Blow and Carmack, as opposed to more enterprise developers like Fowler and Bob, favor strong static typing for bug prevention and increasing readability. Uncle Bob (Robert C. Martin) thinks unit testing can replace static typing. Blow counters with that it brings the additional cost of extra code, which makes refactoring more expensive, in contrast to static typing combined with larger granularity test. All recognize the cost of typing, so tools like type inference or at least gradual typing have a merit.

Strong, Weak, Static, Dynamic Definitions

Strongly typed languages apply strict type checking at compile time, while weak typing does not. Static typed language apply type checking at compile time, while dynamic typing languages apply them at runtime and use automatic type conversion. For example, Jonathan Blow’s Jai is static/strongly typed C-style language.

Dynamic Static
Strong Python, Ruby, Closure, Erlang Java, C#, C++, Scala, TypeScript, Haskell
Weak JavaScript, PHP, Visual Basic, Perl C

Clarity Of Typed Code

Most agree that strong static typing increases code readability and clarity.

I found the lack of type information on parameters made life difficult - I kept saying to myself 'what exactly do I have here?' I didn't find this so much of an issue in Smalltalk for two reasons: the excellent environment makes it easy to fire up a debugger and see what you have, and secondly the common convention is to name the arguments after the type.
Anything that isn’t crystal clear to a static analysis tool probably isn’t clear to your fellow programmers, either. The classic hacker disdain for “bondage and discipline languages” is short-sighted – the needs of large, long-lived, multi-programmer projects are just different than the quick work you do for yourself.
Everything that is syntactically legal that the compiler will accept will eventually wind up in your codebase. And that's why I think that static typing is so valuable because it cuts down on what can kind of make it past those.
If you don't have like serious static type checking like you have in a language like C++ then once you start doing a non-trivial amount of stuff it becomes very easy to make mistakes. And it becomes very hard to find the mistakes easy to make mistakes.
Another area where static typing is useful is that it allows programming environments to be much more helpful. The revelation here (as in so many things) was IntelliJ. With an IDE like this I really felt the type system was helping me. Even simple things like auto-completion are greatly helped by static types, and leading IDEs can do much more than that.

Type Checks: Compilation, Type Linting, versus Tests

There is a disagreement, about the cost of unit tests compared to flexibility with fewer tests with static typing.

the success that we have had with code analysis has been clear enough that I will say plainly it is irresponsible to not use it.
Statically typed strongly statically typed programming languages let you do this thing, that things like Lua for example don't let you do, or you just break your program. Very useful technique that you can't do in Python or Javascript or any of this other stuff. ... The type safety part of Python or the lack thereof is huge. A lot of the stuff that we did today these grunt work refactors that I'm doing would be a lot scarier in Python. Because you'd be like: I don't know if I just broke something. We've done 10 things today at least where you'd be like yeah I don't know if that broke something. We're in C++ you're like: Yeah, I know, I didn't break something.
But I discovered that in the presence of SelfTestingCode, most bugs that static types would have were found just as easily by the tests. Since the tests found much more than type errors, you needed them in either a static or dynamically typed language, so having the static typing gave you little gain.
Whether you use static, or dynamic typing, you must still demonstrate correctness by executing tests. Static typing does not reduce that number of tests, because those tests are behavioral and empirical.
this whole thing about TDD about writing the test before you write the code is nonsense because you don't exactly know what you're building yet if you're doing anything interesting ... The more code you have, the less agile you are, and unit tests add a great deal of code. So changing things it's like tar. It's keeping you stuck and keeping you from changing things. ... If you can test the thing not as a unit - for example as an entire game. That might be a much more efficient way of testing in terms of the number of hours you put into programming. ... Testing is very important. If you don't test your software then your software doesn't work. What I'm saying is I don't think that this obsessive unit testing is the right way to test.

Is Strong Static Typing Fun?

Most note that static typing is less fun.

I see the lure the enticement of having just throw random types onto anything about not having to you know have sort of template typing arrangements and things you're there's a there's an appeal to that, but I think that it bites you in the end. If the code lives a long time, and it grows enough. I think that the value of types is just super, super important and that's something that's good.
Whatever the reason, this better flow leads to more fun programming - even with an inferior environment. This may not seem to matter much, who cares if programmers have fun?
At the beginning it seems really easy because you just type some stuff, and it works.

This last line is dedicated to Bash, which has no types whatsoever.

Created on 19 Aug 2022. Updated on: 17 Aug 2022.
Thank you

About Vaclav Kosar How many days left in this quarter? Twitter Bullet Points to Copy & Paste Averaging Stopwatch Privacy Policy
Copyright © Vaclav Kosar. All rights reserved. Not investment, financial, medical, or any other advice. No guarantee of information accuracy.