4 ms·
I have a 1134 line function with zero tests defined for it sitting open in the background which most likely scores something like 32 out of 11 on that list. I'm
by Hansi 13y ago
I have a 1134 line function with zero tests defined for it sitting open in the background which most likely scores something like 32 out of 11 on that list. I'm afraid of touching that monster...
- steveklabnik 13y agoI use 'break out method object' from "Working Effectively with Legacy Code" in these situations: 1. Create a new class for the computation 2. Define a method on that class to do the new work. 3. Copy the body of the old method over, and change variable references to instance variables. 4. Give it an initialize method that takes arguments to set the instance variables used in step 3. 5. Make the old method delegate to the new class and method. Now, at least, it's isolated into once place, and you can use your other refactoring tricks without affecting global state, like extract method. I'm not sure if this is the _best_ example, but I wrote about this a few years ago, in Ruby: http://blog.steveklabnik.com/posts/2011-09-06-the-secret-to-rails-oo-design http://blog.steveklabnik.com/posts/2011-09-06-the-secret-to-...
- tetha 13y agoIf you touch it, it will never work again. Even if you revert all your changes.
- precisioncoder 13y agoI've had this happen often enough that when refactoring something tricky I like to copy the function and rework it. Then I'll change references from the old method to the new one one at a time and test. One of my favorite methods returned a Map<Long, Map<Long, Map<Long, Map<Long, Long>>>> with no comment explaining what any of those Long values were...
- Hansi 13y agoMy thoughts exactly. Needs to be done though unfortunately. I'm going to get some chainsaws and duct tape and attack it on Monday. Mondays suck anyway so it can't make the day much worse.