The Story of the Book

Java by Comparison did not start as a book. It started in a classroom, with a simple question: how do you teach others to write clean code?

  1. 2011

    Two new Java courses

    At the University of Bamberg, Simon Harrer and Jörg Lenhard designed two courses: Advanced Java Programming and Programming Complex Interactive Systems, a course on concurrency on the JVM.

    A typical university course has a theoretical lecture, a plenary exercise, homework, and a written exam. Students hand in a solution and get a grade. That teaches them to make code work. It does not teach them to write code that others can read and change.

  2. The question

    How do you teach clean code?

    Our answer was code review, in three steps:

    1. Experience code reviews interactively, in class.
    2. Receive detailed written code reviews on every assignment.
    3. Perform code reviews yourself.

    Students worked in groups on real programming assignments, and every submission came back with a detailed review of what was wrong, how to do it better, and why the better way is really better.

  3. 2011–2016

    The same mistakes, again and again

    In six years, we

    • 500+assignments reviewed
    • 1,000,000+lines of Java read
    • 1000sof times flagged the same issues

    Every new generation of students made the same mistakes, and we wrote the same explanations. So we started a collection of typical errors, each as a comparison of flawed and improved code, to point students to instead of writing it all again.

  4. 2016

    A teaching award, and 80 out of 80 points

    The course concept received the faculty's teaching award. For the first time, a student group scored 80 out of 80 points. Simon and Jörg handed the course over into competent hands, and it was time to look for new challenges.

  5. The idea

    "Can we make something great out of it?"

    Six years of reviews had produced a format that worked: every comparison has an actionable name, the bad code with a problem description, and the better code with a solution description.

    The anatomy of a comparison: actionable name, bad code with problem description, better code with solution description
    The anatomy of a comparison

    We proposed the book to The Pragmatic Bookshelf. Three days later, we had the contract.

  6. 2016–2018

    18 months of writing

    • 3authors
    • 18months
    • 16technical reviewers
    • 300+beta readers

    Together with an editor, a copy editor, a layouter, and a foreword, we turned the collection into 70 comparisons in nine chapters, from cleaning up booleans to preparing code for the real world.

  7. March 21, 2018

    Java by Comparison is released

    Enthusiastic reviewers and happy readers followed: reviews in magazines, blogs, and podcasts in five languages, and the authors told the story in talks at meetups and conferences, always ending with a round of Comparison Jeopardy, a game where the audience finds the name of a comparison.

  8. 2019 and later

    Beyond the book

    2025: Java by Comparison is one of the books in the Bartz v. Anthropic copyright settlement, the class action over books used to train Anthropic's Claude models. So, in a way, its 70 comparisons live on in Anthropic's frontier models.

    The research behind the teaching concept is published in peer-reviewed papers: see the research page.