Hacker News new | ask | show | jobs
by IshKebab 3695 days ago
Two main reasons:

1. You can detect very common errors (e.g. typos) at compile-time instead of maybe detecting them at run-time. This makes the code much much more reliable (or equivalently you don't need to do nearly as much testing).

2. Dynamic typing prevents IDEs from doing extremely useful things like real code completion and symbol renaming.

If you're thinking "but I edit Javascript with code completion" or "code completion isn't such a big deal" then it's probably because you've never used accurate code completion, e.g. Microsoft's Intellisense for C++, or pretty much an Java IDE.

3 comments

There are ways to deal with that in dynamically typed languages.

1) Common Lisp implementation use a compiler to detect typos, etc.

    CL-USER 21 > (defun bar () (fo0))
    BAR

    CL-USER 22 > (compile *)

    The following function is undefined:
    FO0 which is referenced by BAR
2) In Common Lisp one can ask the running Lisp system for information about classes, symbols, functions, etc.

The use cases for renaming are also completely different. If you take for example a Java class and you want to rename an attribute and update the getter/setters you might want to use a 'tool'. In a dynamically typed language like Common Lisp, this is often not necessary because code generation is widely used and changes can be propagate that way.

0. Performance. 3. Interface documentation.
Also static types tell the machine what is supposed to happen next, and always. Dynamic types represent possibilities that have to be maintained as open until they become commitments that have to be remembered. Static types are certainties that come as orders. Dynamic typing is like being in love, Static typing is like being in the Army.

(disclaimer, I have never been in the Army or any military force and the above post is based on my imagination and watching films)