Book Review : Effective C++
Some time ago, I have read Accelerated C++. After this introductory book, I have chosen to read a book focused on the good practices of C++ development. On that purpose, I bought Effective C++ Third Edition from Scott Meyers. I already finished this book months ago, but I didn't found the time and the movitation to review it until now.
First of all, this book is aimed for people who already know C++ development and want to improve their skills in this language and especially to produce better programs and designs. This book can also be used by C developer that just switched to C++. The book is organized around 55 specific guidelines. Each guideline describe a way to write better C++.
The guidelines are grouped into nine chapters, each of which focus a specific part of program development and design. The guidelines and the chapters are not specially made to be read in a specific order, but some of the guidelines are referring to other ones. However, I recommend that you read the guidelines in the given order, but you can also choose the guidelines or chapters that interest you the most.
The first chapter is an introduction of the C++ language. You will learn that C++ is not only a single language, but a multiparadigm programming language. The book will also show some errors that should be avoided when we are used to the C programming language.
The second chapter focuses on the constructors, the destructors and the assignment operators. Indeed, there are several rules that should be followed when declaring those things for a class, especially when talking about inheritance. For example, this chapter will teach you how and why to prevent exceptions from leaving destructors. This chapter will also talk about the copy constructors.
In the next chapter, you'll learn how to manage resources in the right way. You'll be introduced to the use of objects to manage a resource, to the RAII (Resource Acquisition Is Initialization) principle and the different forms of the new and delete operators. The point of storing newed (dynamically allocated) objects is also addressed.
The fourth chapter is about designs and declarations. Basically, you'll learn how to declare interfaces that are easy to use in the right way (and hard to use incorrectly, as the author says). More than just interfaces, you'll see how to treat class design as type design, so that your classes can be used like any other type in your C++ code (overlading operators is a way to achieve this goal). You'll also learn how to declare a good function signature that can be used without any problem.
Now that you know how to declare a good interface or a type, it's time to implement it. In the Implementation chapter, you'll see how to declare variables in the right way and how to avoid excessive casting. An important part of this chapter is the management of exceptions in your functions. Namely, you'll learn what are the different exception-safety levels for the functions and how to provide the best levels for your functions.
The next chapter is focused on inheritance and object-oriented design. You'll learn when and how to use inhenritance in your classes and how to avoid virtual functions when it is possible by several ways and patterns that are proposed by the author. The chapter shows also that some things are not meant to be inherited and that multiple inheritance should be used judiciously.
The seventh chapter talks about templates and generic programming. Compile-time polymorphisme will be addressed. After the reading of this chapter, you'll knwo how to declare and define a good function template. You'll also know how to use traits classes to get information about types at runtime. Last but not least, this chapter contains also an introduction about Template Metaprogramming (TMP).
The eighth chapter will teach you how customize the new and delete operators to reach your needs in memory management. This is the most specific chapters of the book and it won't be useful to everyone, but that's interesting to read it once to know what happens in the background.
Finally, the last chapter contains miscelleanous items, especially what libraries you should try to familiarize you with to improve your code even more or to avoid reinventing the wheel.
In my opinion, this book is a must-have for every beginner and medium C++ developers. All the guidelines will help you produce a better code and to avoid the most common traps that this language contains. I'm sure that after the reading of this book, your code will improve greatly.
Comments
Comments powered by Disqus