{"id":2868,"date":"2022-07-11T10:02:25","date_gmt":"2022-07-11T04:32:25","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2868"},"modified":"2022-07-11T10:02:25","modified_gmt":"2022-07-11T04:32:25","slug":"book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/11\/book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code\/","title":{"rendered":"Book Review &#8211;  Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code"},"content":{"rendered":"<p><em><strong><span style=\"color: #0000ff;\">Title:<\/span> <\/strong><\/em>Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code<\/p>\n<p><span style=\"color: #0000ff;\"><em><strong>Authors:<\/strong><\/em><\/span> J.Guy Davidson, Kate Gregory<\/p>\n<p><span style=\"color: #0000ff;\"><em><strong>Publisher:<\/strong><\/em><\/span><span class=\"Apple-converted-space\">\u00a0 <\/span>Pearson Education<\/p>\n<p><span style=\"color: #0000ff;\"><em><strong>Year:<\/strong><\/em><\/span> 2022<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2870\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/11\/book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code\/book-cover2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg\" data-orig-size=\"1394,1798\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1657530347&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2-794x1024.jpg\" class=\"size-medium wp-image-2870 alignleft\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?resize=233%2C300&#038;ssl=1\" alt=\"\" width=\"233\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?resize=233%2C300&amp;ssl=1 233w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?resize=794%2C1024&amp;ssl=1 794w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?resize=768%2C991&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?resize=1191%2C1536&amp;ssl=1 1191w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2.jpg?w=1394&amp;ssl=1 1394w\" sizes=\"(max-width: 233px) 100vw, 233px\" \/><\/a><\/p>\n<p>My earliest introduction to C++ guidelines was through <em><strong>Scott Meyers\u2019<\/strong><\/em> excellent book <em><strong>Effective C++<\/strong><\/em> that first appeared in 1992. After programming in C++ for around 3 years at that point, the book made a lot of sense to me. Of course, C++ continued to evolve and <em><strong>Scott Meyers<\/strong><\/em> published updated versions of the book. Another book along similar lines is <em><strong>C++ Coding Standards<\/strong><\/em>, by <em><strong>Herb Sutter<\/strong><\/em> and <em><strong>Andrei Alexandrescu<\/strong><\/em>. A few other books that teach the essentials of C++ devote a couple of chapters to good programming tips (please see the last section of this article). Overall, there is no dearth of books on C++ guidelines and coding standards.<\/p>\n<p><em><strong>C++ Core Guidelines<\/strong><\/em> was initially announced as an open source project on <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\" target=\"_blank\" rel=\"noopener\"><em><strong>GitHub<\/strong><\/em><\/a>\u00a0by <em><strong>Bjarne Stroustrup<\/strong><\/em> and <em><strong>Herb Sutter<\/strong><\/em> in 2015. There have been several contributions from others as well and the project is quite alive and active. The present book,\u00a0<em><strong>Beautiful C++,<\/strong><\/em> discusses in detail 30 of these core guidelines.<\/p>\n<p>This book is not meant for beginner C++ programmers. Read the book only if you have a fairly good understanding of a majority of the C++ language features and have done some serious programming. Otherwise, some of the ideas won\u2019t sink in.<\/p>\n<p>The book presents 30 guidelines in 5 sections, each section containing 6 chapters. Each chapter is devoted to a single guideline. The sections do not directly correspond to the section labelling used in the core guidelines, but when a guideline is taken up for discussion, the book mentions the associated core guideline section label for easy reference. <span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Given that the authors of this book have rich experience in C++, the detailed explanation of each guideline along with numerous examples helps us understand how the guideline contributes to code quality. Although I felt that in some cases the explanation was a bit verbose, I am sure it will appeal to a wider audience.<\/p>\n<p>I guess it is OK to disagree with some of the core guidelines as long as you understand their true purpose. As an example, I might not take the guideline <em><strong>\u201cES.10: Declare one name (only) per declaration\u201d<\/strong><\/em> seriously. I believe it is a matter of style and taste. However, the authors explain clearly why this guideline makes sense and I very much appreciate that.<\/p>\n<p>The guideline in Chapter 2.6, <em><strong>\u201cT.120: Use template meta programming only when you really need to\u201d<\/strong><\/em> might surprise some C++ programmers because <em><strong>TMP<\/strong><\/em> is generally considered <em><strong>fashionable<\/strong><\/em> and is supposed to be a special feature of <em><strong>Templates<\/strong><\/em>. However, the authors&#8217; explanation along with relevant examples is quite convincing. One of the valid arguments put forth by the authors is that because <em><strong>TMP<\/strong><\/em> is a compile-time feature, debugging the program can be difficult.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>I definitely enjoyed going through all the guidelines, but the one I loved most is Chapter 5.5\u00a0<em><strong>\u201cPer.7: Design to enable optimization\u201d<\/strong><\/em>. Using the simple and well-known example of <em><strong>qsort<\/strong><\/em> function, the authors gradually refine its interface, each time explaining why it makes sense. It is difficult to forget the guideline after reading this chapter!<\/p>\n<p>The book includes topics from almost all the important sections in the core guidelines. I would have loved to see a few more from the <em><strong>Concurrency and Parallelism<\/strong><\/em>\u00a0section, but then that is just my preference. Overall, the authors have done a great job of covering important guidelines.<\/p>\n<p>Another commendable effort by the authors is that the complete sample code included in the book is available for experimentation with the popular <a href=\"https:\/\/godbolt.org\/z\/cg30-ch0.0\" target=\"_blank\" rel=\"noopener\"><em><strong>Compiler Explorer<\/strong><\/em><\/a>.<\/p>\n<p>Adopting guidelines such as the ones included in this book will definitely go a long way in improving the quality of C++ code that we write. I strongly believe that companies and teams should establish proper code review procedures (automated and\/or manual) as part of the QA process to ensure the guidelines are followed. The good news is that <em><strong>Visual Studio 2020<\/strong><\/em>, for example, includes a <em><strong>static code analyzer<\/strong><\/em> that can be configured to check for violations of the core guidelines in a project. Eventually, compiler support will become widely available and that would immensely benefit developers.<\/p>\n<p>If you program in C++ for a living, then this book is a <em><strong>must-read<\/strong><\/em> and more importantly, <em><strong>must-follow<\/strong><\/em>! I hope the authors will come out with a sequel explaining the remaining core guidelines.<\/p>\n<blockquote>\n<h3 style=\"text-align: center;\">Recommended Additional Reading<\/h3>\n<p>1) Clean C++ 20: Sustainable Software Development Patterns and Best Practices (2nd Edition), Stephen Roth, Apress, 2021.<\/p>\n<p>2) Embracing Modern C++ Safely, John Lakos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith, Pearson Education, 2022.<\/p>\n<p>3) Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C+14, Scott Meyers, O\u2019Reilly, 2014.<\/p>\n<p>4) C++Coding Standards: 101 Rules, Guidelines, and Best Practices, Herb Sutter and Andrei Alexandrescu, Addison-Wesley, 2005.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>Have a wonderful week ahead!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Title: Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code Authors: J.Guy Davidson, Kate Gregory Publisher:\u00a0 Pearson Education Year: 2022 My earliest introduction to C++ guidelines was through Scott Meyers\u2019 excellent book Effective C++ that first appeared in 1992. After programming in C++ for around 3 years at that point, the book [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[94,49],"tags":[326],"class_list":["post-2868","post","type-post","status-publish","format-standard","hentry","category-book-review","category-c","tag-c-core-guidelines"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Kg","jetpack-related-posts":[{"id":2915,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/09\/18\/book-review-embracing-modern-c-safely\/","url_meta":{"origin":2868,"position":0},"title":"Book Review: Embracing Modern C++ Safely","author":"admin","date":"September 18, 2022","format":false,"excerpt":"Title: Embracing Modern C++ Safely Authors: John Laos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith Publisher: Pearson Education, Inc. Year: 2022 C++ is a complex language. Fortunately, we have several good books (and other online material) for programmers at various levels. A few weeks ago, I had reviewed and recommended\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/09\/Book2-235x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1496,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/03\/10\/book-review-c-concurrency-in-action\/","url_meta":{"origin":2868,"position":1},"title":"Book Review: C++ Concurrency in Action","author":"admin","date":"March 10, 2019","format":false,"excerpt":"Title: C++ Concurrency in Action Author: Anthony Williams Publisher: Manning Publications Co. Year: 2019 (Second Edition) \u00a0 The first edition of this book came out in the year 2012 and covered the concurrency features of C++ 11. Much has happened since then. The present C++17 is significantly richer in terms\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1339,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/23\/book-review-real-time-c\/","url_meta":{"origin":2868,"position":2},"title":"Book Review: Real-Time C++","author":"admin","date":"December 23, 2018","format":false,"excerpt":"Title: Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming Author: Christopher Kormanyos Publisher: Springer-Verlag Year: 2018 (Third Edition) It was the title of this book which caught my attention a few weeks ago and I decided to invest in it. I am not in to real-time software development these days,\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":980,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/07\/08\/book-review-the-modern-c-challenge\/","url_meta":{"origin":2868,"position":3},"title":"Book Review &#8211; The Modern C++ Challenge","author":"admin","date":"July 8, 2018","format":false,"excerpt":"Title: The Modern C++ Challenge Author: Marius Bancilla Publisher: Packt Publishing Year: May 2018\u00a0 This week I have been going through a new book titled The Modern C++ Challenge written by Marius Bancilla. The book is a collection of programming problems (along with suggested solutions) targeting C++ . The title\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3249,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/11\/06\/book-review-c-initialization-story\/","url_meta":{"origin":2868,"position":4},"title":"Book Review: C++ Initialization Story","author":"admin","date":"November 6, 2023","format":false,"excerpt":"Title: C++ Initialization Story - A Guide Through All Initialization Options and Related C++ Areas Author: Bart\u0142omiej Filipek Publisher: Leanpub Year: 2023 Can you believe that there is a language where \u201cinitialization\u201d itself involves many subtleties and a whole book can be devoted to this topic? Yes, modern C++ is\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/11\/Book-cover-231x300.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":293,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/08\/07\/is-deriving-from-a-concrete-class-bad\/","url_meta":{"origin":2868,"position":5},"title":"Is Deriving from a Concrete Class Bad?","author":"admin","date":"August 7, 2016","format":false,"excerpt":"In my first post on Julia, I noted that the language does not allow deriving from a concrete (i.e., non-abstract) class. It definitely came as a surprise because in most OO languages (C++, Java, Scala, C#, etc.) such a restriction does not exist. It is true that when you design\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2868"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2868\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}