Every developer has a number of requirements in mind that she considers prerequisites for good or clean code. As long as a piece of code doesn’t violate any of these requirements, it qualifies as good or clean from the viewpoint of the developer. Different people have different requirements. And programming languages differ, of course. But still, for a given language, there’s typically a set of “core” requirements and best practices. These are aspects that the community of developers recognizes and accepts, even if they aren’t written down explicitly. In this book, we’re trying to provide you—someone who might not yet be aware of many of the practices in the Java community—with a set of best practices for clean code in Java.
As a beginner, your list of requirements for good Java code might be as short as this one:
- The code must compile. \t
- The output must be correct.
These items are about the functional correctness of your program, but they don’t tell much about the quality of your code. An experienced programmer cares about a lot more than that, and her checklist is much longer. She just needs a quick glance at a piece of code to detect flaws, bad naming, hard-to-test methods, inconsistencies, bad practices, and much more.
The aim of this book is to train your brain to internalize more checklist items, helping you on your way to becoming an experienced and professional programmer. Each of the items in this book represents such a checklist item.