Jonathan. Frech’s WebBlog

Book review: A Tour of C++ (#234)

Jonathan Frech,

Avidly writ­ing C as well as golfing in it for over two years, I decided to venture out further in the realm of C-descendent languages, trying to get a foothold in C++.
How­ev­er, contrary to many oth­er languages with their own closed communities, style guides, best practices and gen­er­al higher ma­chine ab­strac­tion induced ease of use, C++ is a dif­fer­ent lan­guage. With a rich his­to­ry spanning mul­ti­ple decades, millions of users from varying backgrounds and the necessity of enabling low-level hard­ware com­mu­ni­ca­tion influencing its de­sign and abil­i­ty to be used ef­fec­tive­ly, it is a daunt­ing task to acquire enough knowledge and ex­pe­ri­ence to successfully write a standards-conforming C++ pro­gram which accomplishes a desired task.
Adding to this the plethora of textbooks supposedly correctly presenting their selected corner of the lan­guage and with that the immense danger of a poorly writ­ten textbook supplying a misleading first impression thus wrecking the fundamental knowledge of the lan­guage as well as the path ahead, I hoped for and succeeded in finding a thought-through, holistic and internally consistent as well as surely correct pre­sen­ta­tion of C++ in A Tour of C++, writ­ten by the inventor of and therefore a rea­son­able authority on C++.

What follows are my thoughts on the book A Tour of C++⁠¹, having begun to read it after on­ly sporadically adjusting single lines in C++ golfs and having used it to facilitate a two thousand line C++ pro­ject⁠² simulating a ficticious 32-bit ar­chi­tec­ture⁠³.
I am in no way affiliated with ei­ther the au­thor Bjarne Stroustrup nor the publisher Pearson (Ad­di­son-Wesley) and purchased the book on my own.

-=-

Stroustrup wrote three C++ textbooks: Programming: Principles and Practice Using C++ (colloquially ‘the swan book’, referring to its cover), which aims to teach programming using C++, The C++ Programming Lan­guage, which aims to cover all of C++, and A Tour of C++ in which a sane and intra-compatible subset of C++ is presented assuming fundamental knowledge of imperative programming. It is the latter that is covered herein.

Mul­ti­ple textbooks with dif­fer­ent target audiences al­low Stroustrup to swiftly cover the bare fundamentals, taylored towards C++-specific aspects: the refrain from an enforced gar­bage col­lec­tion system and its hard­ware-conscious de­sign to name two. He goes on to cover custom extensions of the type system by use of im­ple­ment­ing a custom std::vector<double> and follows up with the lan­guage’s structural fa­cil­i­ties. His custom container is used to briefly cover ob­ject-oriented hierarchical de­sign — treating ob­ject orientation as a lan­guage fea­ture rather than its identity — and extends said container using template-driven generality. With a few oth­er necessary features sprinkled into the story of im­ple­ment­ing a custom std::vector, the core of C++ is covered by page 105, at the book’s halfway point.
Equal­ly important to an un­der­stand­ing of a lan­guage’s core is a broad knowledge of its stan­dard li­brary components — especially in a lan­guage like C++ where the stan­dard li­brary itself is standardized and an in­te­gral part of the lan­guage. Thus, with a slight detour into the land of regular expressions, the stan­dard li­brary’s platform-agnostic I/O mod­el for both character streams and files is shown to­geth­er with the least specialized stan­dard containers and algorithms which operate upon them. Following algorithms, some miscellaneous yet useful li­brary contents are presented, closing with two terse chapters on numerics and concurrency.
As its final chapter, A Tour of C++ offers some historic perspectives to both the origins from C with classes to the arduous path of becoming the standardized, modern and ca­pa­ble lan­guage C++ is today.

Throughout the book, soon to be expected fa­cil­i­ties of the C++20 stan­dard as well as ones to hopefully arrive in C++23 or beyond are mentioned and properly framed inside the cur­rent C++ landscape. Stroustrup does not hesitate to call out certain iffy historic remnants but puts them in an adequate con­text to provide a holistic tour of C++, as the title promises.

A Tour of C++ offered an enjoying read; antithetical to the technical nature of the topic at hand, a collected and concise writ­ing style paired with playful aspects such as chapter-opening quotes and occasional tongue-in-cheek remarks about aspects of C++ or oth­er languages⁠⁴ help the book not to be­come a stale checklist of features, motivating a thorough read. End-of-chapter advice and intra-doc­u­ment references help to form a tight­ly interconnected un­der­stand­ing of the primary pillars of C++ de­sign.
At times, Stroustrup’s syntax of choice can at times seem quaint, being K&R-inspired as well as white­space-meager, yet this style is used consistently throughout the book and not too far off of what is seen ‘out in the wild’. After some initial C-induced C++ syntax hesitance, I was able to accomodate — devising my own C++ syntax flavor and successfully realizing my ficticious ar­chi­tec­ture simulation pro­ject.⁠⁵


[1]Stroustrup, Bjarne: A Tour of C++, second edi­tion, third print­ing. Boston: Person (Ad­di­son-Wesley), March 2019.
[2][2020-11-19] I previously misstated this statistic as “five thousand”; refactoring may have removed a substantial amount of lines. Measuring non-blank lines of code, cat *.cpp *.hpp | grep -v '^$' | wc -l outputs 2131 in Joy Assembler v1.0.
[3]See https://github.com/jfrech/joy-assembler.
[4]Some of my favourite lines:
  • p. 5: “C++ offers a small zoo of fundamental types, but since I’m not a zoologist, I will not list them all.”
  • p. 40: “That’s pretty crude and inflexible, but often suf­fi­cient.”
  • p. 73: “My ideal is not to create any gar­bage, thus eliminating the need for a gar­bage col­lec­tor: Do not litter!”
  • p. 88: “For reasons lost in standards committee politics, this use of auto is not cur­rent­ly allowed for func­tion arguments.”
  • p. 208: “C++ is not the work of a faceless, anonymous committee or of a supposedly omnipotent “dictator for life”; it is the work of many dedicated, experienced, hard-working individuals.”
[5]See https://github.com/jfrech/joy-assembler.