This book aims to teach you how to write cleaner, more elegant code in Java. It covers 70 issues of various topics with before and after comparison in a concise, easy to read and understand way.
The authors are teachers of Java programming courses. When they were evaluating students' assignments, they had to provide the same feedback for the same common issues over and over. A checklist with common issues and proper solutions would help a lot as they could only reference an item from this list when evaluating the assessments. That's how the idea for this book was born. It is a list of common issues and code smells in Java and what can you do to fix them.
The idea is simple. The book contains 70 independent items. Similar items are grouped into categories, such as comments, testing or exception handling. Each item covers a specific issue, such as "Always Catch Most Specific Exception".
Each item is not just a recommendation or a best practice. Instead, it starts with a problematic snippet of code, which works but has some smells. Then there is a description of what is exactly wrong and why.
On the next page there is a the original snippet, fixed according to a proposed best practice and an explanation of what changed and why is it better.
What is really useful is that the layout of the book consistently keeps each item just on two pages - on the left you can see the problem and on the right the solution. This makes it really easy to compare both at the same time.
I find this format very suitable. First of all, you have specific examples with code, both before and after applying the recommended best practices, which is way easier to understand than just an abstract recommendation. Having the problem presented first also gives you a nice opportunity to think about what's wrong before you are given the answer. This leads to better understanding and deeper learning than just reading recommended best practice outright.
Each item is independent of each other, which makes it easy to skip what you already know. You don't necessarily need to read this book front to back. This makes the book an ideal reference for mentoring and code reviews as you can easily point others just to a specific item.
Even though the items are technically independent, some code examples are further polished over the course of multiple items, which gives a better sense of continuity and understanding how multiple issues relate to each other.
Since each item needs to fit to exactly two pages, the writing style is concise and to the point, while still being easy to understand.
This book can be very useful to developers with various skill levels for different reasons.
If you are just starting with programming and Java and you're still struggling with basic concepts and syntax, this book may not be for you yet. In fact, at the beginning of the book there is a FizzBuzz test, which is supposed to determine whether you are ready for this book or not. If you are still in very early stages of learning Java and programming, you may want to wait a bit with this book until you grasp basic concepts. Only after learning some basics, you can understand how to write code which not only works, but is also clean and elegant.
You'll get most of this book as a junior Java developer or a person who is switching to Java from another language.
For intermediate devs, this still is useful. You can use the book as a refresher for what you already know and there should still be much to learn from it. Moreover, since the items are independent, you can just skip some items.
As a senior developer, you may not learn much yourself, but the book is a great resource when mentoring others or when doing code review. You can just point them to a specific item when reviewing their code.
The book works with Java 8, so it does not really matter if you're not familiar with all the newer versions of Java.
The book consists of 70 items divided into 9 chapters.
The first two chapters cover basic Java constructs such as iteration, conditions, enums, constants and more. Generally how to write cleaner code, which is less error-prone and easier to understand.
The third chapter covers comments. It guides you through which comments are useless and do more harm than good. Then what should be commented and how. On top of that, some JavaDoc specific advice.
The fourth chapter is dedicated to naming. It is very important to make sure your code is readable and easy to understand. And of course, as we know, "There are only two hard things in Computer Science: cache invalidation and naming things.".
The fifth chapter is focused on excepting handling.
The sixth chapter covers unit testing with JUnit 5. I was pleasantly surprised to see a topic like this in the book as it is not part of the core Java, but of course, it is very important nonetheless. And it is nice to show to beginners early on that testing is important.
The next chapter describes the object-oriented design. The topic is so broad that this book cannot meaningfully cover it on just a few pages.
Lambda expressions and streams are the topics of the eight chapter. It is a nice introduction to the topic with several useful good practices.
The last chapter breaks the usual format and offers a taste of other development areas, which you will encounter in the real world. There is static code analysis, continuous integration, team collaboration, logging, concurrency and more. If you already have some work experience, it may not be anything new. However, it offers a nice intro to the real world development if you are still preparing for your first job.
I really enjoyed this book and I wish I had a book like this when I was starting with Java. It can be a great resource early in your career. It is easy to read, short, easy to understand and can be a good book to read before more heavy-weight titles such as Effective Java or Clean Code, which can be intimidating and harder to grasp when you are just starting.
In your early days, it can also be useful as an introduction (although very brief) to some related real-world topics such as testing, continuous integration or static code analysis. Overall I do recommend this book especially for junior developers, who will benefit from it the most.
To help you decide whether this book is worth getting and reading, there are several free content examples available for free for you to check:
- Return Boolean Expressions Directly
- Document Using Examples
- Split Method with Boolean Parameters