Experienced object-oriented programmers eager to produce code of a better quality will greatly appreciate this book. Although the title mentions Java, the advices, discussions, and analyzes offered go well beyond the scope of Java. The content of this book provides coding recommendations for a wide spectrum of practices ranging from general programming (e.g., favoring interfaces over reflection) to Java-specific aspects (e.g., good use of annotation , enumeration, and generics). This book is not suitable for beginners since it requires a solid software engineering experience to fully grasp its content.
Each chapter consists of items, each item providing a well detailed coding style recommendation. The 11 chapters elaborates on 78 items in total. Chapter 2 is about objets creation and destruction. Favoring object factories instead of ad-hoc constructors and avoiding pitfall of obsolete references are the essence of this chapter. Chapter 3 discusses how and when to compare objects. It provides a comprehensible description of hashing functions and how to write them. It also makes a good case why hashCode() must be redefined when providing a new equals().
Chapter 4 is about classes and interfaces. Enforcing encapsulation is well exemplified. Chapter 5 is a more Java specific by being about Generics. It shows how to avoid code pollution with unchecked warnings and why lists should be favored over arrays. Chapter 6 is also very Java specific by discussing the usage of enums and annotations. Chapter 7 discusses several aspects of method design (how to treat parameters, return values, how to design and document method signature).
Chapter 8 discusses notions of general programming such as local variables, control structures, libraries and data types. Chapter 9 provides guidelines for using exceptions effectively. Among the different tackled items, it provides a nice discussion about the three kinds of throwables (checked exception, runtime exceptions, and errors) and the principle of failure atomicity. Chapter 10 contains advices to help you write clear, correct, well-documented concurrent programs. Concurrency is a hard topic that is addressed by providing reasonable, simple but effective advices. Chapter 11 discusses objects serialization. A notable feature of this chapter is the serialization proxy pattern which can help to avoid many of the pitfalls of object serialization.
The book is very pleasant to read. For example, most of items are introduced with a small code excerpt preceded with a “can you spot the bug?”. This raises the interactivity the book can have with its readers.
Most of the advices provided in this book are refreshing and some are though-provoking. Most of modern IDEs provides automated checks on source code. “Effective Java” will help programmers to understand the rational behind some of those checks.
All that said, this book is a must for Java and non-Java programmers. The significant amount of knowledge this book compiles makes its reading worth.
Aucun commentaire:
Enregistrer un commentaire