R – Under what circumstances are dynamic languages appropriate

dynamic-languagesprogramming-languages

I have used static languages such as C#, Java, C and some done some work in Javascript which is a dynamic language.

Contrary to the popular belief, I find myself writing code faster in C# than in Javascript (and that could be because I have more experience in C# compared to javascript)

So, what I want to understand is that what are the places where the dynamic language is appropriate and can be favored over the static languages.

Can a dynamic language be used for the Enterprise system which needs to be maintained for years to come or, its mostly used for use and throw codes?

Best Answer

I'd use a dynamic language anytime simplicity and flexibility count more than performance and explicitness. Static typing gives the compiler a lot of information that can be used to write really fast assembly code. It also makes contracts explicit, possibly making sections of code easier to reason about in isolation. However, because these contracts are so explicit and have ripple effects through so much code they're somewhat hard to change. In systems that need a high degree of flexibility, this can lead to a lot of complexity being created to get around the rigidity of static typing.

Personally, I don't see the lack of static type checking to be that big a deal. Of course, failing at compile time is the ideal fast failure. However, the dynamic language paradigm isn't really bad. When a type error occurs at runtime in a dynamic language, things fail immediately and with explicit error messages. You don't just get weird undefined behavior and a failure in some completely different place.

On the other hand, I find that a good template system (not C++) and static type inference can be an absolute godsend. This allows you to have the best of both worlds, as it's basically compile time dynamic typing. Everything still gets statically checked at compile time. Errors are caught early and efficient assembly code is generated. Nonetheless, you retain the flexibility of not having to make contracts explicit at design time. My understanding is that Haskell, OCaml, etc. do this quite well. If you're interested in a language with a more mainstream look and feel that does this, try D.

Related Topic