|
|
|
|
|
by paulbaumgart
5857 days ago
|
|
With dynamically typed languages and implicit variable declarations, I find the most common runtime errors are, in descending order of frequency: * Something returned null when I assumed it would return a value/object.
* I used the wrong variable.
* I made a typo in an assignment that implicitly created an unused variable
(this is easy to catch with static analysis even in dynamically typed
languages, admittedly).
The first one is by far the most common.I'm not particularly experienced with Haskell, but my understanding is that the static typing will usually catch the second one and that more advanced static analysis (more advanced than type checking) can easily catch the third one. Most important, though, is the case of the first and most common error. Here, the language will very explicitly require you to handle the case that "Nothing" will potentially be returned. So, most of the sorts of errors that would have caused failed execution in a dynamically typed language will be caught at compile time. This means that when the program runs, it will usually be closer to being correct than it would be if it were written in a dynamically typed language and failed in the middle of execution. |
|
Using the wrong variable, I just never seem to have that problem as well named variables make the code just look wrong when it happens and secondly because I'm writing the code while the code is running in a live environment. I see immediately when it does work because the first thing I do is execute it on a live object to make sure it does what it's supposed to do. This handles the null issue as well. Incremental live development just side steps about all of these issues, and is something static languages just don't let me do.
More often than not, I've found type systems to prevent me from expressing what I want to express even when the code would work perfectly fine simply because polymorphism isn't granular enough. In dynamic type systems, polymorphism is based on method signature alone and is not bound to any kind of class/interface/type class which gives me the most flexibility in expressing myself. I prefer that flexibility and incremental live development over any gain any static type system might give me.