Tuesday, April 17, 2012

Refactoring Responsibly - 360Flex Preso

Here is the slide deck (pptx) from my 360Flex refactoring preso.... Refactoring Responsibly

If you want to see the embedded version without the cool animations:



There we also some questions that I'll do my best to remember and try to answer again.

Q: Did you come up with the "First Draft" idea for coding / programming?
A: As far as I can tell, I couldn't find any other references to it on my searches. It was an idea that developed as a result of trying to sell upper management on the idea that we needed to refactor.

Q: What about refactoring to improve performance?
A: Performance is a whole different animal. If you are looking to get major performance gains, you might need to do more re-writing than cleaning up. You will probably want functional tests to be your characterization tests. And yes, the characterization tests add more function calls, which will probably cause *some mild* performance degradation. But then the choice is readable maintainable code, or performant code. Usually these things are orthogonal. As a side note, once you have tests in place, you have an open field with high confidence of what you can do. If you redesign, get better performance, and the tests still pass, then awesome. (And if you do redesign and the tests still pass, welcome to test driven design :) it is a great thing)

Q: What if I come back and do my second draft the next day, do I still need tests?
A: You are testing your code in some way. Whether it is manually executing the actions or running automated tests. If you write your 2nd draft the next day, that is a different level of refactoring then I'm talking about. I'd call that a good idea on the code that you were creating. You aren't in production yet, you are adding a feature or fixing a bug.... you are still developing and while working on the problem, you thought of a better way to do it. Clearly however you verified that your code worked yesterday is still clear in your mind, and you can easily verify that it works today. I'm a TDD and automated test advocate, so I'd say yes you need tests, but if that is not part of your philosophy, then it is up to you to decide the maintainability of your code

Q: Doesn't refactoring admit that you screwed up the first time.
A: NO! As the Refactoring Prime Directive states : "Regardless of what we discover, we understand and truly believe that everyone did the best job they could, given what they knew at the time, their skills and abilities, the resources available, and the situation at hand. "

Q: Could you slow down next time?
A: I certainly will ;)