|
|||||||||
Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition) (Addison-Wesley Professional Computing Series) by Scott Meyers
$41.80
|
C++ Programming Style (Addison-Wesley Professional Computing Series) by Tom Cargill
$40.49
|
The Annotated C++ Reference Manual by Margaret A. Ellis
$47.96
|
The C++ Programming Language: Special Edition (3rd Edition) by Bjarne Stroustrup
$60.36
|
More Effective C++: 35 New Ways to Improve Your Programs and Designs (Addison-Wesley Professional Computing Series) by Scott Meyers
$40.50
|
This book is designed to help programmers who have already learned C++ develop their programming expertise. To understand how programmers achieve proficiency, we need to understand not only how people learn a new language (such as a programming language), but also how a language is used to solve software problems effectively. Learning Programming Languages
Not everything you need to know about a product is described in the owner's manual. Before the arrival of our first child, my wife and I were admonished by a friend that no book, and no training, could completely prepare us for the art of parenting. We must of course learn minimal, essential skills. But the interesting, challenging, and rewarding aspects of raising a child go beyond this basic knowledge. For example, no book or "owner's manual" will help you understand why your three-year-old daughter rubs toothpaste in your one-year-old's hair, or why your children hang their socks in the refrigerator.
The same is true of programming languages. Programming language syntax shapes our thinking to a degree, but what we learn in the "owner's manual" about syntax alone only gets us started. Most of what guides the structure of our programs, and therefore of the systems we build, is the styles and idioms we adopt to express design concepts.
Style distinguishes excellence from accomplishment. An effective parenting style, or programming style, comes from personal experience or by building on the experience of others. A software engineer who knows how to match a programming language to the needs of an application, writes excellent programs. To achieve this level of expertise, we need to go beyond rules and rote, into convention and style, and ultimately into abstractions of concept and structure. It is in that sense that this book is "advanced."
The rules, conventions, and concepts of programming drive the structure of the systems we build: They give us a model of how to build systems. A model for problem decomposition and system composition is a paradigm, a pattern for dividing the world into manageable parts. C++ is a multiparadigm language. C programmers use C++ as a better C. Object-oriented advocates do everything polymorphically. In fact, a variety of approaches is usually necessary to express the solution to a software problem efficiently and elegantly.
Learning a programming language is much like learning a natural language. Knowledge of basic syntax lets a programmer write simple procedures and build them into nontrivial programs, just as someone with a vocabulary of a few hundred German words can write a story far richer than see-Dick-run. But mastery of language is quite another issue. That such stories are nontrivial does not make them elegant or demonstrate fluency. Learning language syntax and basic semantics is like taking a 13-hour course in German: It prepares you for the task of ordering a bratwurst, but not for going to Germany to make a living, and certainly not for getting a job as a German language journalist or poet. The difference is in learning the idioms of the language. For example, there is nothing in C itself that establishes
while (*cp1++ = *cp2++);
as a fundamental building block, but a programmer unfamiliar with this construct would not be perceived as a fluent C programmer.
In programming, as in natural language, important idioms underly the suitability and expressiveness of linguistic constructs even in everyday situations. Good idioms make the application programmer's job easier, just as idioms in any language enrich communication. Programming idioms are reusable "expressions" of programming semantics, in the same sense that classes are reusable units of design and code. Simple idioms (like the while loop above) are notational conveniences, but seldom are central to program design. This book focuses on idioms that influence how the language is used in the overall structure and implementation of a design. Such idioms take insight and time to refine, more so than the simple notational idioms. The idioms usually involve some intricacy and complexity, details that can be written once and stashed away. Once established, programming language idioms can be used with convenience and power. The Book's Approach
Assuming a background in the basic syntax of C++, this book imparts the proficiency that expert C++ programmers gain through experience by giving a feel for the styles and idioms of the language. It shows how different styles let C++ be used for simple data abstraction, full-fledged abstract data type implementation, and various styles of object-oriented programming. It also explores idioms that the core of the C++ language does not directly support, such as functional and frame-based programming, and advanced garbage collection techniques. The Book's Structure
Rather than taking a "flat" approach to learning the advanced features of C++ by organizing around language features, this book looks at these increasingly powerful abstractions from the perspective of the C++ features required to support them. Each chapter of this book is organized around a family of such idioms. The idioms progressively build on each other in successive chapters.
Chapter 1 provides a historical perspective on C++ idioms. It provides some motivation as to why idioms came about, and varying degrees to which different idioms can be thought of as part of the language or as outside the language.
Chapter 2 introduces the fundamental C++ language building blocks: classes and member functions. Though much of the material is basic, the chapter establishes idioms and vocabulary that recur in later chapters. It introduces compiler type systems, and their relationship to user-defined types and classes, from a design perspective. It also presents idioms that make const more useful.
Chapter 3 introduces idioms that make classes "complete" types. C++ has been evolving to automate more and more of the work of copying and initializing objects, but programmers still need to customize assignment and default constructors for most nontrivial classes. This chapter provides a framework for that customization. I call the idioms described in this chapter canonical forms, meaning that they define principles and standards to make the underlying mechanics of objects work. In addition to the most commonly used canonical form, idioms are presented to apply reference counting to new and existing classes. These are the first idioms of the book to go beyond straightforward application of the base C++ syntax. A variation on reference counting, counted pointers, is shown as a way to move C++ a step further away from the machine, abandoning pointers in deference to smarter, pointer-like objects. Lastly, the chapter looks at how to separate the creation of an object from its initialization. To someone familiar with basic C++, this might seem an unnatural idiom: C++ tightly couples these two operations. The need to separate them arises in the design of device drivers and in systems with mutually dependent resources.
Chapter 4 introduces inheritance; Chapter 5 adds polymorphism to inheritance to introduce object-oriented programming. Many new C++ programmers get "inheritance fever," using it at every occasion. While it is true that inheritance is used mostly to support the object paradigm, it has a distinctly separate application for software reuse. Introducing inheritance apart from polymorphism helps the reader separate the two concepts and avoids the confusion that often arises from trying to internalize two foreign concepts at once.
Chapter 6 approaches the constructs, styles and idioms of C++ from the perspectives of architecture and design. It examines what classes mean at the level of an application, high above the level of syntax. Appreciating the relationships between the design abstractions of an application, and between the classes and objects of its implementation, leads to systems that are robust and easily evolved. Another key to evolution is broadening designs beyond a specific application, to cover applications for a whole domain; guiding principles for domain analysis are an important part of this chapter. The chapter contains numerous rules of thumb about appropriate use of inheritance, an area of difficulty for inexpert C++ programmers. Readers who have been exposed to object-oriented design will appreciate the explanation in this chapter of how to transform the output of design to C++ code. Encapsulation as an alternative to inheri