Ok, I'm not trying to start a flame war here, and I know the argument between static and dynamic languages has been hashed out many times, including here. But I have a very practical question that hopefully someone here can shed some light on. Sorry for the length, but this is not a simple question with probably not a simple answer.
Ruby, PHP, and Javascript are pretty popular languages these days, and they have a lot of people that defend them and argue that being dynamically typed doesn't hold the developer back. I'm new to these languages and would like to start using them for bigger projects, but here's a basic refactoring scenario that comes up all the time at work(work == C#), and I'm wondering what the approach would be in Ruby - I chose Ruby because it's OO.
Ok, I'm using Ruby, and I build a Customer object. It has methods for loading/saving/deleting from the database. It is good and people use it. I add more methods for other things and people use it more. I add a method for calculating order history based on some parameters. By now this class is being used all over the system. Then, one day I decide to change the parameters on the GetOrderHistory method. So I:
- add the new parameters to the method
- rewrite the code of the method to use the new parameters
- change the client code I had in mind to pass the new parameters and use this modified method
But now what? I have dozens/hundreds/whoknows how many other places in the system that need to be changed. In a dynamic OO language like Ruby or Javascript, how would I go about this?
Off the top of my head, not knowing Ruby very well, I can think of two dumb answers:
- 100% Code coverage. I test the entire app and every time it breaks I see if it's that method and fix it
- Find and Replace. I use the text search to look for that method. But I could have other objects with the same method names.
So is there a good answer to this? It seems the IDE would have a hard time. If I had code such as
c = Customer.new
it would be able to figure it out, but what if it's
c= SomeFunctionThatProbablyReturnsACustomerButMightReturnOtherThings()
So what approach would you Ruby experts take in this case?