What kinds of applications or features/requirements make a good case for the use of a dynamic language like Python or Ruby, instead of a static language like Java or C#?
(Aside from apps that require scripting capability, I might say.)
The term "dynamic language" is a pretty broad term so I'll assume this question refers to both programs that do compile time stuff during runtime (e.g. metaprogramming) and dynamically typed languages.
A lot of apps that are currently done in static languages can be done better in dynamic languages. The big one here would be web application development, mainly because ORMs and Front Controllers can be simplified via metaprogramming. There's also the option of using DSLs for testing and other aspects of web development.
Sure, it's no silver bullet and you won't see an order of magnitude improvement over static languages, but with the right technology and people, you would see significant improvements in productivity.
Which leads us the the limitations of dynamic languages, namely technology and people.
If your client's platform (or the client himself) doesn't support dynamic languages, then it's obviously not a good use case. Also, if you need to interface with existing systems outside of open protocols, going with the existing system's language is a better choice.
Then there's the people. An average Java developer wouldn't know the pros and cons of dynamic typing and closures, let alone metaprogramming. Many of them are also unwilling to learn, as evidenced by stories/jokes of devs sticking with one language for the rest of their lives. Without proper mentoring, these developers will keep on doing the things they used to do in their previous language regardless if it's appropriate or not.
When Java developers started programming in Ruby some years back, it wasn't a pretty sight. :P
answered Dec 17 '09 at 11:39
answered Dec 17 '09 at 05:31
In The Rails Way, Obie Fernandez described a use case that in my opinion is better implemented using a dynamic language.
His example involved modifying class instances on the fly. On the database, wherein each table row maps to a class instance, there is a column named "config". This column contains code - methods, etc. - that is eval'd when the row is instantiated.
Let me explain with my own example. Note that I haven't used this technique before, but this is how I imagine I'd use the Obie Fernandez technique.
Imagine a role-playing game, wherein you control a space ship. Some space ships will have the classic_warp_engine, some may have the warp_nine_engine, and an elite few may be equipped with the uber_secret_stolen_from_the_romulans_warp_engine. Code-wise, they have the same interface: ship.engage_warp_drive(). But the engines behave differently: they activate different animations, and different sound effects.
And the beauty here is that the differences between the engines is in the database, not in the code. If you want the uber_secret_romulan_warp_engine to have a 30% chance of blowing up when used, but only for the user named "radamanthus", just change the database row for user radamanthus. No code changes required.
answered Dec 16 '09 at 11:58