Saturday, February 28, 2015

Scala Developers Barcelona TDD introduction session

Two weeks ago I facilitated an introduction to TDD in a Scala Developers Barcelona event.

First, I gave a very short introductory talk about TDD, (these are the slides).

After the talk, I coded a simple exercise to help the attendants get a feeling of the TDD flow.
I tried to stress the importance of creating a list of examples first and choosing the next test so that the code could grow in small steps. I also talked about wishful programming, going from red to green quickly and the importance of refactoring to sustainable TDD.

I used Clojure to code the exercise.

I feel that, somehow, using Clojure got in the way of the message I wanted to transmit. Next time I'll use a language which is more familiar to all the attendants.

This is my solution to the exercise in Clojure where you'll find commits after each passing test and each refactoring, so you can follow the process.

Finally, we started doing TDD with a simple kata.

Ignasi, Jordi and I were all the time visiting the different pairs, helping with doubts about TDD or Scala and commenting with them how their solutions were growing test after test.

I think that during this time I had the chance to clarify some things that hadn't come across before because of the lack of familiarity with Clojure.

At the end, we had a short debate about TDD.

I'd like to thank the Scala Developers Barcelona organizers for inviting me to facilitate this dojo. I had a great time and I hope that, the attendants could get something useful from it in spite of my using Clojure for the first example.

I'd like to also thank all the attendants for coming and Álvaro for telling the Scala Developers Barcelona organizers about me.

Monday, February 16, 2015

Clojure Developers Barcelona: Introductory talk about Clojure functions

Last week I gave a talk about Clojure functions for some of the Clojure Developers Barcelona study group members.

This is the the code I showed on Lightable to explain a bit about Clojure functions:

I had a great time and learned a lot preparing this talk.

During the talk I mentioned some destructuring techniques I had explained more deeply in a previous talk.

This time there were many more attendants than in previous events of the group which is really great.

Thanks all for coming!

I hope we'll go on learning together in next events.

Thursday, February 12, 2015

Kata: Password validator in Clojure

I've just done the Password validator kata in Clojure.

It's a basic kata that, in my opinion, is very useful to think about how we choose the next test so that it helps us grow the code in small steps.

In this kata you have to validate a password.

The conditions that it has to fulfill to be valid are:
  • It should have more than 6 characters
  • It should contain at least one upper case character
  • It should contain at least one lower case character
  • It should contain at least one underscore
  • It should contain at least one numeric character
These are my tests using Midje:

and this is the final version of the code:

I used a mix of TDD and work on the REPL to code it.

To document the process I commited the code after every passing test and every refactoring and also commited the REPL history.

You can find the commits step by step here and the code in this repository in GitHub.

Friday, February 6, 2015

Using underscore.js to simplify a JavaScript code

I'd like to show how using underscore.js library can simplify a JavaScript code.

This is the original code:

It wasn't tested, so I wrote some tests before start refactoring it:

Once I had the tests in place, I separated the responsibility of converting strings into dates from the traversing of the object:

and extracted it to another factory:

that I could directly test: Finally I used underscore.js library to simplify all the JavaScript plumbing that was happening in the object traversing inside DateStringsInsideObjectsIntoDates convert function: By separating the traversing and conversion responsibilities and by using underscore.js, I managed to get to a much more readable version of the code.

Sunday, February 1, 2015

Kata: LCD Digits in Clojure

I've just done the LCD Digits kata in Clojure.

In this kata you have to create an LCD string representation of an integer value using a 3x3 grid of space, underscore, and pipe characters for each digit.

Each digit is shown below (using a dot instead of a space)
._.   ...   ._.   ._.   ...   ._.   ._.   ._.   ._.   ._.
|.|   ..|   ._|   ._|   |_|   |_.   |_.   ..|   |_|   |_|
|_|   ..|   |_.   ._|   ..|   ._|   |_|   ..|   |_|   ..|


Example: 910

._. ... ._.
|_| ..| |.|
..| ..| |_|
These are the tests using Midje:

and this is the resulting code:

I used a mix of TDD and REPL-driven development to code it.

To document the process I commited the code after every passing test and every refactoring and also commited the REPL history.

You can find the commits step by step here and the code in this repository in GitHub.