| > I really haven't seen much benefit in static typing in regards to software defect rate or quality Hold it right there. I've never seen anyone argue that static type systems prevent bugs. I mean they do prevent silly bugs that occur from mistyping variable/property names but I've never seen anyone claim that they eliminate other classes of bugs. The biggest benefit of static type checking is you know what all the variables are. def checkout_cart(customer, payment_methods, cart, session):
# body
What the hell is customer? What is payment methods? What fields are available on these objects? What methods can you call on them? no freaking idea.Of course, this kind of code is confusing in Java as well, but for a different reason: Java conventions encourage a kind of obtuse programming style where everything is hidden behind layers of abstractions of factories and managers, so that even when everything is typed, you're not sure what anything is doing because all the data that matters is private and so are all the methods that actually do anything useful. All you're left with is an abstract interface that can sometimes be just as bad as an untyped variable. But this is mostly a cultural problem. (I've digressed). > Static typing make auto complete and refactoring tools easier, for sure, but it also slows down ease of experimentation Java slows down ease of experimentation because it requires tons of boilerplate code for even the simplest tasks. It's not the static type checking. If anything, static type checking helps experimentation because you can change your mind quickly and the compiler will help you catch all the stupid mistakes that can occur from mismatching types or mistyping variable names. This removes a huge cognitive tax and makes programming more enjoyable. Although I will concede this is subjective. |
Really? I see this every single time the subject is brought up. And, to be fair, they do catch some bugs, it's just that they do so at a cost.
>What the hell is customer? What is payment methods? What fields are available on these objects? What methods can you call on them? no freaking idea.
And, if they are all strings, how much more of an idea do you have?
Static typing does not necessarily help solve this problem - a combination of reduced scope(i.e. looser coupling), more specific variable naming and higher cohesion (e.g. having a customer object) do.
Moreover, there's a super easy way to figure out what all of those things are and figure out how you want to change it - run a behavioral test and launch a REPL when it hits that function.
At that point you can inspect customer, use autocomplete on it and even experimentally run code.
>If anything, static type checking helps experimentation because you can change your mind quickly and the compiler will help you catch all the stupid mistakes that can occur from mismatching types or mistyping variable names. This removes a huge cognitive tax and makes programming more enjoyable.
Behavioral tests perform this function equally well, if you have them.