| Everything has a cost. If you had to pick between "write 99% correct code in 1 week" vs "write 100% correct code in 1 year", you probably would pick the former, and just solve the 1% as you go. It's an absurd hypothetical, but illustrates that it's not just about correctness. Cost matters. What often annoys me about proponents of static typing is that they sound like it doesn't have a cost. But it does. 1. It makes syntax more verbose, harder to see the "story" among the "metadata". 2. It makes code less composable, meaning that everything requires complex interfaces to support everything else. 3. It encourages reuse of fewer general types across the codebase, vs narrow scoped situational ones. 4. It optimizes for "everything must be protected from everything" mentality, when in reality you only have like 2-5 possible data entries into your system. 5. It makes tests more complex to write. 6. Compiled languages are less likely to give you a powerful/practical REPL in a live environment. For some, this loses more than it gains. Also, albeit I haven't seen this studied, human factor probably plays bigger role here than we realize. Too many road signs ironically make roads less safe due to distraction. When my code looks simple and small, my brain gets to focus better on "what can go wrong specifically here". When the language demands I spend my attention constructing types, and add more and more noise, it leaves me less energy and perspective on just taking a step back and thinking "what's actually happening here". |
"write 99% correct code in 1 week and then try to fix it as you go, but your fixes often break existing things for which you didn't have proper tests for. It then takes you total of 2 years to finally reach 100% correct code."
Which one do you choose? It's actually not as simple as 1 year vs 2 years. For a lot of stuff 100% correctness is not critical. 99% correct code can still be a useful product to many, and to you it helps you to quickly validate your idea with users.
However, the difference between static and dynamic typing is not that drastic, if you compare dynamic typing to an expressive statically typed language with good type inference. Comparing, for example, Python to C++ is not really fair as there are too many other things that make C++ more verbose and harder to work with. But if we compare Python to for example F# or even modern C#, the difference is not that big. And dynamic typing has a costs too, just different.
1. "Story" can be harder to understand without "metadata" due to ambiguity that missing information often creates. It's a delicate balance between too much "metadata" and too little.
2. Too much composability can lead to bugs where you compose wrong things or in a wrong way. Generic constraints on interfaces and other metaprogramming features allow flexible and safer composability, but require a bit more tought to create them.
3. Reuse is similar. No constraints on reuse, doesn't protect you from reusing something in corner case where it doesn't work.
4. (depends on how you design your types)
5. Dynamic languages require you to write more tests.
6. F# and C# for example both have REPL.
Quality statically typed language is much harder to create and require more features to be expressive, so there are less of them or they have some warts and they are harder to learn.
It's a game of tradeoffs, where a lot of choices depend on a specific use case.