All Posts

Functional Design Patterns in Scala: 1. Monoids

Monoids are used to describe an aggregation pattern: whenever we need to combine values of a particular type, a monoid instance helps abstract the mechanics of the aggregation from the program’s business logic. In this post, we will use the LCD Digits kata that we tackled previously as a motivating example for applying this pattern. The goal here is to transform a sequence of input digits into a string resembling their representation on an LCD display.

Agile Estimation For Distributed Teams

The teams I’m working with use Planning Poker to estimate the size of user stories. This has proved to be an extremely useful activity, and we rely on it to plan upcoming work. In the past, we used special card decks for this, which worked well when everyone was based in the same room. However, with team members now distributed across two continents, this quickly became less effective. To address this, we initially tried running the sessions over a conference call, using group chat channels to record votes on the items being discussed.

Steve Reich’s Clapping Music with Akka

Using functions to express musical ideas is nothing new: Harmony, time signatures, the relations between notes in a scale and musical form all have their roots in mathematics, and composers have used mathematical abstractions for millennia (see Pythagorean Tuning for a 2500-year-old example). These abstractions, however, are not always obvious from they way that music is written down, leading to a potential disconnect between composer and performer. In this post, we will use Steve Reich’s 1972 Clapping Music to show how functional programming can be used to capture an underlying musical idea.

LCD Digits Kata with Scala

I recently attended one of the coding dojos run by the London Scala User Group. It was great fun, and I’d recommend getting involved to anyone who’s interested in meeting other developers and learning more about scala and functional programming. After breaking into groups, we set about tackling the ‘LCD Digits’ problem from cyber-dojo.org. Although fairly straightforward as a programming challenge, it offers a number of ways to experiment with different functional idioms. The goal is to write a program that takes an integer, and formats this as a string composed of the ‘.’, ‘_’, “|’ and ” ” characters so that the output resembles an LCD display.

Turbocharge Your Mocking Framework With PowerMock

As mentioned in my last post, I am an ardent fan of the Mockito Framework. Originally developed as a fork of EasyMock, it equips developers with the tools to create mock objects using clean and expressive code. In this post, we will show how PowerMockcan be used alongside Mockito (or EasyMock) to create mocks for classes that appear at first ‘unmockable’. Suppose we have the following class: …which has a dependency on a DataProvider:

Using Reflection To Create Mock Objects

Well-established tools like Mockito and EasyMock offer a powerful range of features for defining and interacting with mock objects. I use both heavily in my unit tests, and would recommend them to anyone looking for a mocking framework. Sometimes, however, a real (i.e. non-proxied) collaborator is called for, or adding third-party libraries may not be an option. In most cases, a suitable object could be instantiated by calling the constructor and setting it as a dependency to the object under test.