Sunday, September 29, 2019

Books I read (January - September 2019)

- Timeless Laws of Software Development, Jerry Fitzpatrick
- Writing to Learn, William Zinsser
- The End of the Affair, Graham Greene
- Beyond Legacy Code: Nine Practices to Extend the Life (and Value) of Your Software, David Scott Bernstein

- Refactoring Workbook, William C. Wake
- Binti, Nnedi Okorafor

- Home, Nnedi Okorafor
- The Night Masquerade, Nnedi Okorafor
- Developer Hegemony, Erik Dietrich
- The Ministry of Utmost Happiness, Arundhati Roy

- Cat on a Hot Tin Roof, Tennessee Williams
- Closely Watched Trains (Ostře sledované vlaky), Bohumil Hrabal
- The Chalk Giants, Keith Roberts
- Behold the Man, Michael Moorcock
- Cutting It Short (Postřižiny), Bohumil Hrabal
- La bicicleta de Sumji (סומכי : סיפור לבני הנעורים על אהבה והרפתקאות), Amos Oz
- The Sheltering Sky, Paul Bowles

- Elsewhere, Perhaps (מקום אחר), Amos Oz
- Liminal Thinking: Create the Change You Want by Changing the Way You Think, Dave Gray

- The Turn of the Screw, Henry James
- A Tale of Love and Darkness (סיפור על אהבה וחושך), Amos Oz
- Touch the Water, Touch the Wind (לגעת במים, לגעת ברוח), Amos Oz
- The Third Man, The Fallen Idol, Graham Greene
- The Little Book of Stupidity: How We Lie to Ourselves and Don't Believe Others, Sia Mohajer
- Slaughterhouse-Five, or The Children's Crusade: A Duty-Dance with Death, Kurt Vonnegut
- The Little Town Where Time Stood Still (Městečko, kde se zastavil čas), Bohumil Hrabal

- Offshore, Petros Márkaris
- Martian Time-Slip, Philip K. Dick
- Give and Take: A Revolutionary Approach to Success, Adam Grant
- Object-Oriented Reengineering Patterns, Serge Demeyer, Stéphane Ducasse and Oscar Nierstrasz

- The Loneliness of the Long-Distance Runner (The Loneliness of the Long-Distance Runner, Uncle Ernest, Mr Raynor the Schoolteacher, The Fishing-boat Picture, Noah's Ark, On Saturday Afternoon, The Match, The Disgrace of Jim Scarfedale, The Decline and Fall of Frankie Buller), Alan Sillitoe
- My Michael (מיכאל שלי), Amos Oz
- The Sirens of Titan, Kurt Vonnegut
- Up the Junction, Nell Dunn
- A Taste of Honey, Shelagh Delaney
- Stumbling on Happiness, Daniel Todd Gilbert
- Surfacing, Margaret Atwood
- Soldados de Salamina, Javier Cercas

- Monday Begins on Saturday (Понедельник начинается в субботу), Arkady Strugatsky and Boris Strugatsky
- Warlight, Michael Ondaatje
- Agile Technical Practices Distilled: A Journey Toward Mastering Software Design, Pedro Moreira Santos, Marco Consolaro, and Alessandro Di Gioia
- Capitalist Realism, Mark Fisher
- Black Box Thinking: The Surprising Truth About Success, Matthew Syed
- Otra vida por vivir (Μια ζωή ακόμα), Theodor Kallifatides
- The fine art of small talk, Debra fine

Monday, July 29, 2019

Playing Fizzbuzz with property-based testing


Lately, I’ve been playing a bit with property-based testing.

I practised doing the FizzBuzz kata in Clojure and used the following constraints for fun[1]:

  1. Add one property at a time before writing the code to make the property hold.
  2. Make the failing test pass before writing a new property.

The kata step by step.

To create the properties, I partitioned the first 100 integers according to how they are transformed by the code. This was very easy using two of the operations on sets that Clojure provides (difference and intersection).

The first property I wrote checks that the multiples of 3 but not 5 are Fizz:

and this is the code that makes that test pass:

Next, I wrote a property to check that the multiples of 5 but not 3 are Buzz (I show only the new property for brevity):

and this is the code that makes the new test pass:

Then, I added a property to check that the multiples of 3 and 5 are FizzBuzz:

which was already passing with the existing production code.

Finally, I added a property to check that the rest of numbers are just casted to a string:

which Id made pass with this version of the code:

The final result.

These are the resulting tests where you can see all the properties together:

You can find all the code in this repository.


It was a lot of fun doing this kata. It is a toy example that didn’t make me dive a lot into clojure.check’s generators documentation because I could take advantage of Clojure’s set functions to write the properties.

I think the resulting properties are quite readable even if you don’t know Clojure. On the other hand, the resulting implementation is probably not similar to the ones you’re used to see, and it shows Clojure’s conciseness and expressiveness.


[1] I'm not saying that you should property-based testing with this constraints. They probably make no sense in real cases. The constraints were meant to make it fun.