Tuesday, December 16, 2014

Talk about Clojure destructuring

Today I gave a talk about destructuring in Clojure for some of of the Clojure study group members.

This is the "clean version" of the code I wrote on the fly on Lightable to explain destructuring:

I had a great time and learn a lot preparing the talk.

I hope this small study group will be help to get the Clojure Developers Barcelona Group up and running again soon.

Thanks all for coming.

Monday, December 15, 2014

Kata: Roman Numerals in Clojure (2nd time)

I've just redone the Roman Numerals kata in Clojure following the advices about test-driving algorithms that Sandro Mancuso gave during his Crafted Code course:
  • Grow an algorithm bit by bit
  • Delay treating exceptions (in this case, because they are more complex)
  • Intentionally cause duplication
  • Focus on simple structures first
The resulting code to convert decimals up to 3999 to roman numerals is much simpler than the code I got the first time I did the kata.

I think the reason is that the first time I started refactoring too soon and that hid the duplication pattern that would have lead me to this simpler solution.

As in the previous version, I extended the kata to also convert decimal numbers over 3999.

This is the resulting code:

and these are the tests using Midje:

To document the TDD process I commited the code after every passing test and every refactor. You can find the commits step by step here.

This time it was a bit easier to derive the algorithm only using strict TDD.

You can find all the code in this repository in GitHub.

Friday, December 12, 2014

Kata: Studious Student in Clojure

Last week Leo Antoli facilitated a kata for Software Craftsmanship Barcelona.

We had to solve the Studious Student exercise.

Leo wanted us to experiment how useful testing is in an exercise like this one, so we divided the group in some pairs using TDD, some pairs testing after writing the code and some pairs not testing at all.

The exercise is a bit tricky as pairs that were not testing discovered at the end, whereas the ones doing TDD or testing after coding discovered early during the process.

After an iteration of one hour, we had a very interesting debate about automatic testing.

This is my solution of the exercise in Clojure:

and these are the tests using Midje:


You can see all the code in this GitHub repository.

I'd like to thank Leo for being so kind and sharing his knowledge with us.

Reading GOOS (IX)

These are the links mentioned in last two weeks conversations about the 12th and 13th chapters:
  1. Posts and Papers
  2. Talks