Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Embracing modern C++ safely
Lakos J., Romeo V., Khlebnikov R., Meredith A., Addison-Wesley Professional, Boston, MA, 2021. 1376 pp.  Type: Book (978-0-137380-35-0)
Date Reviewed: Apr 5 2022

This book on C++ is for professionals involved in large-scale projects. It describes various features in C++11 and C++14 with respect to safety, including safe, conditionally safe, and unsafe features. For each feature, descriptions, some historical perspectives, code listings, use cases, pitfalls, annoyances, and references are described.

Chapter 0 looks at factors affecting safety decisions: “severity of known deficiencies,” “difficulty in teaching,” “experience level required for ... proper use,” and “risks associated with ... misuse.” The chapter also guides readers on how to use the book.

Chapter 1 begins by noting that abstractions (annotations) can be used for achieving portable code across C++ compilers and static analyzers. It clarifies angular brackets and decltype use via examples. It discusses the implicit generation of special member functions (constructors, destructors, copy, move), including ways to default them, and continues the discussion with delete features. The authors note that implicit conversions can be problematic and recommend explicit conversions. They discuss the guarantee of no data races for concurrent use of function-scope static variables. The chapter goes on to cover unnamed or local types in templates and briefly describes noreturn standard abstraction, long long type, nullptr, override, unicode string literals, and raw string literals. It also introduces compile-time assertions and extended typedefs. After discussing safe C++11 features, the chapter turns to safe C++14 features: binary literals, member initializers, the standard attribute for indicating deprecated, digit separation for single quotes, and applying templates on variables.

Chapter 2 begins by discussing how to use align. It covers compiler inferred types for auto variables, compile-time function evaluations using constexpr, initializers and explicit-instantiation declarations using extern templates, and initializers with braces for user-defined types and containers. An explanation of plain old data features in C++11 follows, including standard layouts, trivial layouts, and the expected data layouts. The chapter also explains the correct ways of inheriting constructors and describes lambda functions/expressions along with capturing, function objects, and callbacks. It discusses exception safety with the noexcept operator, which can ask if an exception will be thrown at compile time, and shows how the efficient moving of objects can be achieved using rvalue references. It covers convenient foreach loops, opaque enumerations, and enumerations with explicit values, and explains how to use user-defined literal operators. The last C++11 feature discussed here is variadic templates. This lengthy discussion includes variable type parameters of templates, associated classes, associated functions, type deductions, and related packing/expansions. On the C++14 side, the chapter shows what restrictions are removed in C++14 for constexpr. Lambda extensions in C++14 are also discussed.

Chapter 3 is on unsafe features. Unsafe features are characterized as having high risk and little value. The chapter talks about the carries_dependency attribute. It shows how the final feature is risky when used for preventing overrides of virtual functions, destructors, and user-defined types. It describes friend function extensions, inline namespaces, exception throwing/not throwing, reference qualifiers, and unions of C++11. For C++14, the auto return of functions and decltype(auto) are described.

The book can be used for training C++ developers in C++11 and C++14--the “modern C++” in the title. The authors have chosen to use the terms “safe/unsafe” instead of “patterns/anti-patterns” or “good practices/bad practices.” At first the word “safety” creates the impression that it is about cryptology or security, or something related to the execution of C++ programs. But the closest is execution related. The provided use cases and pitfalls can be utilized in C++ programming projects to find what will save development/maintenance times. It is intended to be used as a reference book for such projects. The book does not talk about anything like network security against network- or web-based attacks. The discussions contain lots of examples, which can help readers use the programming language features more effectively and in better ways. The C++ language itself is such that programmers can fall into writing things that are not easily understood by others. This can harm team projects. Following the references in a book like this, however, can help to increase productivity.

Reading a book of this size from cover to cover--more than 1300 pages--would take a long time. Instead, readers can refer to use cases and pitfalls related to their specific projects.

More reviews about this item: Amazon

Reviewer:  Maulik A. Dave Review #: CR147427
Bookmark and Share
  Reviewer Selected
Featured Reviewer
 
 
C++ (D.3.2 ... )
 
Would you recommend this review?
yes
no
Other reviews under "C++": Date
Discovering modern C++
Gottschling P.,  Addison-Wesley Professional, Boston, MA, 2021. 576 pp. Type: Book (978-0-136677-64-2)
Mar 11 2022
Modern data mining algorithms in C++ and CUDA C
Masters T.,  Apress, New York, NY, 2020. 228 pp. Type: Book (978-1-484259-87-0)
May 5 2021
Beginning C++17: from novice to professional (5th ed.)
Horton I., Weert P.,  Apress, New York, NY, 2018. 771 pp. Type: Book (978-1-484233-65-8)
Sep 16 2019
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright © 2000-2022 ThinkLoud, Inc.
Terms of Use
| Privacy Policy