There is quite an interesting discussion going on at Artima about the age old subject of static and dynamic languages. I found the following quote particularly interesting:

Maybe we should look more closely at the kind of programs being written in Ruby and Python and Javascript, and the way good programmers use those languages, to understand if there are reasons that refactoring might seem less obviously helpful in those languages.

I’ve read and written a lot of reasonably long (> 10,000 lines of code) programs in various dynamic languages (Python, Ruby, PHP and more obscure ones as well) and I haven’t seen any evidence that refactoring is less needed in these languages.

Granted, these listings sometimes have constructs that would take more code to write in Java, but here is the catch: if you are using a more expressive language, you don’t write shorter programs, you write programs with more functionalities in them. And at the end of the day, you face the exact same problem that Java and other statically typed languages face: you need to refactor if you want your code to evolve.

I feel much more comfortable refactoring Java code than I do Ruby or Python. It doesn’t even matter whether I authored that code and how confident I am about the test coverage. I just know that I can’t rely on the compiler and the type system to catch my mistakes, and this impacts my productivity immensely. Suddenly, I’m more hesitant and I’m afraid to break something with my changes.

Here are a few select quotes from this discussion that match my own experience very closely:

What I find in Python is that I can barely reuse my old code, much less modify it without a lot of pain. (James Watson)

I, at least, find that my Ruby or Javascript code degrades over time more than my Java code does, mainly because I get lazy and avoid refactorings that I would be more likely to do if they were safer and more automatic. (Alan Keefer)

Ultimately, I have found that big programs written in dynamic languages don’t age as well as those written in a statically typed language because developers are more afraid to refactor them. And rightfully so, since certain refactorings are just plain impossible to achieve automatically in these languages (another reason why duck typing is too dangerous to use in large scale projects).

The bottom line is actually fairly simple: nothing beats a dynamic language to write a prototype, but if you know that the code will have to be maintained and that it will be in use for several years, the initial cost of using a statically typed language is an investment that is very quickly amortized…