refactoring

Recursos de programación de refactoring
Álvaro García and I were pairing yesterday after work.We practised coding the Rotate an array in place kata in Python.It was great fun and we discussed about naming, scaffolding tests, closures, free variables and deleting tests.Once back at home, I redid the kata in JavaScript. You can see the resulting code in GitHub. I commited every time I got to green and after every refactoring so you can follow the process.In this post I just want to highlight what Álvaro and I did to optimize the code a...
This is my solution to the Beer song problem in Clojure:I wrote a first version using just regular functions:and a second one using multimethods:I enjoyed refactoring the code once all tests were passing. I also practised how to use multimethods and how to pass parameters with default values.You can nitpick my solution here or see all the exercises I've done so far in this repository. - por Garajeando
Last weekend I did the UglyTrivia legacy code refactoring kata in Java.Before starting to refactor, I added a characterization test to describe (characterize) the actual behavior of the original code. Since the only "visible effects" of the code were the lines it was writing to the standard output, I had to use that output to create the characterization test.This is the code of the characterization test:Although in this final version, the expected output reflects the fixing of two bugs in the or...
I've just solved the UglyTrivia legacy code refactoring kata in Java which was the kata we did in the last Barcelona Software Craftsmanship event.This is the initial version of the Game class: And this is the code after my refactoring:Update:And this is the code after I revisited it again (Feb. 27th 2016): Check my solution in GitHub with commits after each refactoring step. - por Garajeando
I've just watched this great live-coding talk by Sandro Mancuso: Testing and Refactoring Legacy Code - por Garajeando
I've just made a small TDD kata in C++ using GoogleMock.I committed the existing code after each green and after each refactoring step.Check the step by step process in GitHub. - por Garajeando
I've recently coded a solution to the StringCalculator kata in C++ using GoogleMock, (you can check its code in GitHub).In one of the refactoring steps, I extracted the code that filters out not numeric tokens to a separated helper method: filterOutNotNumericTokens:Once all the kata requirements were satisfied, I refactored this method a little bit more using C++11 copy_if algorithm:We can use the same technique to refactor the method that ignores numbers greater than 1000, ignoreTooBig, from th...
I've just made a small refactoring kata in C++.Some of the tests in the initial code* were very slow because their code had to sleep some time in order for them to pass. Some other tests relied on having certain environment variable set to a given value.The behavior that checked the environment variable and the one related to time were embedded in the Course class.Through refactoring this behavior was isolated and extracted so that it could be injected into Course and then two fake classes were...
Last Monday I hosted an event for Barcelona Software Craftsmanship community. We practiced refactoring and learned about ports and adapters using Matteo Vaccari's Birthday Greetings kata in refactoring mode. This is the initial code in Java that we tried to refactor.I prepared several slides to introduce what we were going to do. I thought that we could just start refactoring for two hours right after this explanation, but, thanks to the suggestions of some attendees, we changed the plan and did...
I've been playing a bit more with scopes to make the generalized version of FizzBuzz using Array.map and Array.join I posted about recently accept substitution rules with any predicate on a number. I also coded a factory function that creates the substitute function.This is the factory that creates a substitute function given a list of substitution descriptions objects which are composed of a predicate on the number and a replacement for the number:Next you can see how this factory is used in th...