Night of the Living Pet Kata

Reimagining the Eclipse Collections Pet Kata with emojis

The PetType class in the Pet Kata now has emojis

The Pet Kata is alive!

It’s been eight years since I first wrote the article which would become the basis for the Eclipse Collections Pet Kata. I’ve taught Eclipse Collections to over a thousand developers using the Pet Kata. The Pet Kata has always had a PetType implemented as a Java enum, but it wasn’t until recently that I was inspired to introduce emojis into the code. Here is the link to the original InfoQ article which was converted into a kata by Nikhil Nanivadekar.

I credit Paul King for inspiring me and a few other Eclipse Collections OSS contributors to begin introducing emojis into code katas I work on. Paul has written a great blog about the Pet Kata that is definitely worth checking out.

The credit for the OSS contribution that introduced the emojis into the Pet kata goes to Emilie Robichaud.

How to use emojis in a kata?

It was simple to introduce emojis into the Pet Kata code base, as you can see from the PetType class above. The challenge once they were included in the PetType enum was to decide how to use them effectively to make the Pet Kata more fun.

The answer was to use them in the tests. Requiring developers to type emojis in code would be very painful. However, seeing them in the existing test structures, would make the code more inviting by adding more color to the tests, and getting rid of extra text code to read.

For example, if we compare two tests in exercise three, you will see the subtle differences. One test uses the PetType enum, the other emojis.

People by PetType

Get people by their PetTypes

People by Pet emoji

Get people by their Pet emojis

I introduced a more fundamental change to the kata when I added an overloaded form of the hasPet method to Person which takes a String. This can be used instead of hasPet with PetType.

Two forms of hasPet

Overloaded forms of hasPet on the Person class

Finding people with PetType.CAT

Using the PetType enum with select in Exercise 1

Finding people with 🐱

Using an emoji with the overloaded hasPet method and selectWith in Exercise 2

JUnit DisplayName

If you look in the test code above you will see the DisplayName annotation used with the unit tests. I was not aware of what this annotation did, until a developer named Rose contributed them to the kata. This has a neat effect in the JUnit Runner in IntelliJ. This is what the tests look like when run now.

Emojis in the JUnit test runner using DisplayName annotation

Emojis in IntelliJ Code Assist

While I was showing the Pet Kata to Mala Gupta in the Hackergarten session I hosted at JavaOne, we discovered the IntelliJ code assist on the PetType enum was a lot more colorful fun. See for yourself.

Typing PetType. with IntelliJ code assist shows the enum values with emojis

The emojis have arrived

If you haven’t tried the Eclipse Collections Pet kata before, or even in a while, it might be fun for you to try. You can learn some things about the Eclipse Collections API, and you might also get inspired to use emojis in your own katas. They certainly have brought some new excitement and energy to our code katas in Eclipse Collections.

Happy Halloween! 🎃

I am the creator of and a Committer for the Eclipse Collections OSS project which is managed at the Eclipse Foundation. Eclipse Collections is open for contributions.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Raab

Java Champion. Creator of the Eclipse Collections OSS Java library ( Inspired by Smalltalk. Opinions are my own.