Java by Comparison

3 minute read

I am very happy to announce the release of “Java by Comparison” by Simon Harrer, Jörg Lenhard and myself published at the Pragmatic Bookshelf. Over the last year we worked hard to write down our experience from programming education in form of a book on Java code quality that is suited for Java learners from their second to third year.

I want to use this opportunity to share the ideas behind the book and how everything came together. Some are also described in the acknowledgments and the preface (named “Welcome!”) of our book, which are available as a preview at the publisher’s homepage.

So, why is there a need for another Java book? After all, there are established classics on code quality like Clean Code or Refactoring, and recently Joshua Bloch released the third edition of Effective Java. When telling our idea to one of my professors in Bamberg, he told me “…that he wouldn’t waste a single minute on writing a Java book, because there are so many excellent books out there and writing another one would be rockstar business”. That was half a year before we signed with PragProg, our first choice publisher.

I think Java by Comparison is different, because of its didactic concepts that make it accessible for learners that are not yet on a professional programming level. Although we love the aforementioned books and have learned so much from them, they are not quite an easy read for a programming novice. Our book basically condenses our combined experience in teaching advanced Java programming courses at university. Having mastered the basic syntax is just not enough to write good code. This needs a professional environment, where code is not only written once and forgotten after the assignment submission (as it often happens at university courses), but is maintained in a team over a prolonged period. It also needs somebody with experience to review the code and give you hints on how to improve it.

In an ideal case, you have a mentor! Somebody who points out and explains to you your mistakes, shows you how to resolve them and gives you an idea why the improvement is actually better than what has been there before. Unfortunately, good mentors are rare and usually have little time. So we wrote a book, which we think can help to learn about Java code quality in the absence of a mentor.

This tweet by David Heinemeier Hansson (the creator of Rails) inspired us to structure our items in the two-page format. When you open the book you will find some flawed code on the left side along with an explanation which is then contrasted to the improved code together with an rationale why the solution is better. On top of this there’s an actionable name (like “Avoid Negations”) that sticks in mind.

Example double page format

Often novices are told to improve their programming skills by reading code written by experts. While in theory it is possible to go to Github and start reading code of open source software, in practice a 2nd year programmer can’t do that without guidance. Furthermore, much code out there is actually of lacking quality. But how can a novice know the difference..?

With the 70 two-page comparisons in nine chapters you will read some code, but not randomly. Instead, each snippet focuses on only one issue that you will learn to memorize and generalize to other code. Plus, you have the direct comparison on how to improve the flawed code, meaning that you not only learn what is bad and good code, but also how to get from the former to the latter.

Thus, this book is also good for junior developers that are about to start their professional programming careers. Before publishing it, we sent it to about 20 technical reviewers both from academia and software industry who thoroughly went through the chapters and reported many issues that were mistakes or where they simply disagreed with our opinion. While their comments improved the quality of the book a lot, they also motivated us to keep going, because several said that they really needed such a book for their students, junior developers and even project contractors.

Enough said: You can buy the book and the DRM-free e-book directly at Pragmatic Programmers, or if you prefer Amazon.com [UK, DE], also over there. We also created a small webpage with more condensed information at java.by-comparison.com.

Updated: