Akka Essentials Book Review

Recently I had the opportunity to read the Akka Essentials book. This post is a brief review of this publication. Hope you enjoy.

The only good thing about this book is that it is short. Ok, that’s an exaggeration, but don’t expect too much from this book. To keep things in perspective, I read the kindle edition of this book this last month – so perhaps some of the problems mentioned below are specific to this version.

First thing I need to say about this book is that, a lot of times, it has at least awkward (to not say wrong) English sentences. It really could use some serious revision here. Some formatting review would also be good: in the “About the Reviewers” section there is even a whole duplicated paragraph.

The book covers lots of stuff about Akka – so it might be a good first glance at what this framework can do. Just don’t trust too much the code samples – more on that in a moment. Another interesting point, which might be good for some people, and bad for others, is that it presents examples both in Scala and Java.

In the sample code, lots of times, the author has slices of code that he uses to explain something. Than he goes on to add the entire code again, in a single unit. This is another point where I guess some people will like, and others won’t. I didn’t – it feels like wasting space that could be used to better explain some concepts.

Now to my pet peeve: a sample message, in an earlier chapter in the book. Try to guess what’s wrong in the code bellow (extracted from the book) before reading on:

import java.util.List;
public final class MapData {
  private final List<WordCount> dataList;
  public List<WordCount> getDataList() {
    return dataList;
  }
  public MapData(List<WordCount> dataList) {
    this.dataList = dataList;
  }
}

We have a class named MapData, whose objects are going to be used as messages to actors. It has a java.util.List attribute which is not guaranteed to be immutable, and no defensive copies are used. The problem with this is that such mutable messages can corrupt the actors, making them unreliable at all – this is even mentioned in the official Akka documentation, and is a serious error: http://doc.akka.io/docs/akka/2.0.5/java/untyped-actors.html – take a look at the “Messages and immutability” section.

In Scala, writing immutable messages is a lot easier, so at least there the author should have a correct message, right?  Unfortunately not. This is his Scala version for the message:

case class MapData(dataList: ArrayBuffer[WordCount])

Oh man… Even the Scala version of the message is wrong! ArrayBuffer is a mutable data structure. You really have to get out of your way to make this error. It is normal for people that are starting to use actors to write this kind of code, but I really expect more from a book trying to TEACH Akka. I wrote a bit about this subject here.

Another thing a bit strange or off-putting in the book is that sometimes it feels like the author is just throwing information at you, randomly. Also, a lot of times, the text says one thing about the code, and the code itself is a bit different from what is mentioned in the text – another clear lack of revision. In one example, when talking about routers for the first time, the author says we could pass messages in a round robin fashion using routers (which is correct). Then he goes on to show a sample code using a … BroadcastRouter! This kind of router has a completely different semantics.

All in all, since I love Akka, I would be happy to be able to recommend this book. The latter chapters even got better then the first ones. But I can’t. You are probably better off just reading the official documentation.

Advertisement
This entry was posted in scala and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s