Monday, April 28, 2014

Books I read (January - April 2014)

January
- Pan, educación, libertad (Ψωμί, παιδεία, ελευθερία), Petros Márkaris
- NW London, Zadie Smith
- 101 cuentos clásicos de la China, Chang Shiru, Ramiro A. Calle
- Mr. Neighborly's Humble Little Ruby Book, Jeremy McAnally

February
- Blankets, Craig Thompson

March
- Practical Object-Oriented Design in Ruby, Sandi Metz
- Modern C++ Programming with Test-Driven Development, Jeff Langr

April
- Learning PHP, MySQL & JavaScript, Robin Nixon
- Measuring the world, Daniel Kehlmann

Thursday, April 17, 2014

Interesting KataCast: "Clojure TDD demo (Robozzle)"

I've just watched this great explained katacast by Brian Marick

The top-down style Marick uses to grow his code through TDD reminds me a lot of how Gregor Kiczales worked through the example programs in Racket of his Introduction to Systematic Program Design - Part 1 Coursera course that I took a while ago.

The difference between the two processes is basically in the tooling, because Midje allows Marick to "stub" the results of helper functions so he can get feedback about his top functions from the very beginning whereas in Kiczales' examples he had to wait until all the helpers were working to see the top functions tests pass.

Apart from that they use the same top-down approach.

Interesting Talk: "Some Thoughts on Classes After 18 Months of Clojure"

I've just watched this great talk by Brian Marick:

Friday, April 11, 2014

Standard Output redirection in Java for a characterization test

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 original code, at the beginning it was just what the original code was writing to the standard output given a fixed seed for the random number generator.

This article describes this technique very well: Working Effectively With Characterization Tests.

To be able to redirect the standard output I used the StandardOutputRedirection class:


The characterization test shown before yielded a code coverage of 93% which gave me confidence enough to start refactoring the code.

Sunday, April 6, 2014

Kata: UglyTrivia legacy code refactoring kata in Java

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.

Tuesday, April 1, 2014

Interesting Talk: "Testing Online Crazy Glue: Strategies for building testable PHP applications"

I've just watched this interesting talk by Chris Hartjes:

Introduced FormEmailService façade and struggling with names again

Following the advice given by One on a comment, I introduced a façade service that encapsulate everything about emails, FormEmailService with FormEmailComposer and EmailSender as collaborators. This simplified the creation of the IntroducedInformation class which was great.

I also followed his suggestion of passing the form object as a parameter to the sendByEmailAndRedirect method.

This was how it was used after that change:

Although the creation of the IntroducedInformation got simpler, I didn't like how it read anymore because an "information thing" was now sending a form.

In the previous version the "information thing" was sending itself using a "Yoda-like" language:

To keep the form as a parameter I decided to rename the class to so it was "something that does something on something" and not finding any better name I went down the road of "SomethingService" names:

Well, it's not perfect but at least I think it reads better than the version where the "information thing" was sending a form.

This is how the class looks now:

and these are its tests:
I keep thinking in a name for this that doesn't follow the "SomethingService" pattern, but until inspiration comes I'll settle on this one.

Thank you very much Carlos, Marcin and José for your feedback. I really appreciate it.