{"id":980,"date":"2018-07-08T11:11:56","date_gmt":"2018-07-08T05:41:56","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=980"},"modified":"2018-07-08T11:17:37","modified_gmt":"2018-07-08T05:47:37","slug":"book-review-the-modern-c-challenge","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2018\/07\/08\/book-review-the-modern-c-challenge\/","title":{"rendered":"Book Review &#8211; The Modern C++ Challenge"},"content":{"rendered":"<p><em><strong>Title: The Modern C++ Challenge<\/strong><\/em><\/p>\n<p><em><strong>Author: Marius Bancilla<\/strong><\/em><\/p>\n<p><em><strong>Publisher: Packt Publishing<\/strong><\/em><\/p>\n<p><em><strong>Year: May 2018<\/strong><\/em><span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>This week I have been going through a new book titled <em><strong>The Modern C++ Challenge<\/strong><\/em> written by <em><strong>Marius Bancilla<\/strong><\/em>. The book is a collection of programming problems (along with suggested solutions) targeting C++ . The title of the book is a bit misleading because the book does not intend to <em><strong>challenge<\/strong><\/em> your knowledge of specific C++ features, but it is a set of (mostly) general problems requiring you to code in C++. As the author himself says, it is possible to use the book as a collection of problems that one can solve in any language.<\/p>\n<p>There are 100 problems in all, distributed over 12 chapters. Problems range from too simple to fairly challenging. For example the first few problems are about finding <em><strong>GCD<\/strong><\/em>, <em><strong>LCM<\/strong><\/em>, etc. It is not clear what kind of <em><strong>C++ challenge<\/strong><\/em> these pose. The author could have chosen more interesting problems instead of these. Later chapters do have interesting problems that require you to put in some effort effort, but I expected more.<\/p>\n<p>Also, I think some of the problem statements are too brief and could have been explained in more detail. For instance, <em><strong>Problem 5<\/strong><\/em> asks you to write a program for printing <em><strong>sexy prime pairs<\/strong><\/em>. Although one can <em><strong>google<\/strong><\/em> and find out the meaning of <em><strong>sexy prime pairs<\/strong><\/em>, it would have been better if it was explained as part of the problem statement itself. Interestingly, the explanation is given in the solution to this problem, but it should be the other way round.<\/p>\n<p>To be fair to the author, the solutions demonstrate good use of C++. I particularly found two things interesting.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>One is that the author prefers to use <em><strong>const<\/strong><\/em> qualifier even for function arguments that are passed by value, for example, you find this code on <em><strong>Page 14<\/strong><\/em>:<\/p>\n<blockquote><p><span style=\"color: #0000ff;\">unsigned int gcd(unsigned int const a, unsigned int const b)<\/span><\/p>\n<p><span style=\"color: #0000ff;\">{<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\">\/\/ Code not shown<\/span><\/p>\n<p><span style=\"color: #0000ff;\">}<\/span><\/p><\/blockquote>\n<p>I am not a great fan of this practice and I don&#8217;t use it. But there are interesting discussions about this usage on the internet and I urge you to take a look (for example, <a href=\"https:\/\/stackoverflow.com\/questions\/117293\/use-of-const-for-function-parameter\" target=\"_blank\" rel=\"noopener\">this<\/a>).<\/p>\n<p>The other<span class=\"Apple-converted-space\">\u00a0 <\/span>thing I liked about the code samples (solutions) in the book is the fairly consistent use of <em><strong>noexcept<\/strong><\/em> specification as part of function declaration, wherever appropriate. <em><strong>noexcept<\/strong><\/em> has been around since <em><strong>C++11<\/strong><\/em> and is the preferred replacement for the old <em><strong>throw()<\/strong><\/em>. The general advice is that you should use this whenever you can (and only when you can!) because it can help the compiler do interesting optimizations (see <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/cpp\/noexcept-cpp\" target=\"_blank\" rel=\"noopener\">this<\/a>).<\/p>\n<p>I also like the fact that the author uses the <em><strong>C++17<\/strong><\/em> library feature <em><strong>std::string_view()<\/strong><\/em> in several examples instead of the traditional <em><strong>std::string()<\/strong><\/em>. The former is an efficient way of constructing a <em><strong>string-like<\/strong><\/em> object without <em><strong>owning<\/strong><\/em> the data. <a href=\"https:\/\/skebanga.github.io\/string-view\/\" target=\"_blank\" rel=\"noopener\">Here<\/a>\u00a0is a good discussion on this topic. If you want the official specification, it is <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string_view\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Of course, the code is not perfect. Although I haven&#8217;t spent sufficient time to understand the finer details of all the code, or think of more efficient algorithms, I feel the author could have compiled the code with extra level of warnings enabled. For example, <em><strong>Problem 32<\/strong><\/em> is about printing <em><strong>Pascal Triangle<\/strong><\/em>. In the solution to this problem, the function <em><strong>number_of_digits<\/strong><\/em> takes an <em><strong>unsigned int<\/strong><\/em> as argument, but at the place of call, it is passed an <em><strong>int<\/strong><\/em> argument. By looking at the code, it is clear that this will not pose any issue because the values are very much within limits. However, I would have expected that someone who takes care to declare <em><strong>by value<\/strong><\/em> arguments as <em><strong>const<\/strong><\/em>, would be careful about this too (make both arguments <em><strong>unsigned int<\/strong><\/em> or just <em><strong>int<\/strong><\/em> to be consistent). This is definitely not to take away credit for the nice book from the author, but is just a harmless observation.<\/p>\n<p>If you are new to C++ and are looking for additional material to reinforce your concepts, then this book will definitely help. C++ being such a complex language, one needs all the help one can get to master the language!<\/p>\n<p>Have a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 of the book is a [&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,17],"tags":[144,118,145],"class_list":["post-980","post","type-post","status-publish","format-standard","hentry","category-book-review","category-c","category-programming","tag-c11","tag-c17","tag-review"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-fO","jetpack-related-posts":[{"id":988,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/07\/22\/book-review-design-patterns-in-modern-c\/","url_meta":{"origin":980,"position":0},"title":"Book Review &#8211; Design Patterns in Modern C++","author":"admin","date":"July 22, 2018","format":false,"excerpt":"Title: Design Patterns in Modern C++ - Reusable Approaches for Object-Oriented Software Design Author: Dmitri Nesteruk Publisher: Apress Year: 2018 Luck has been on my side for the past few weeks; I have been getting access to nice books to read. I wrote about The\u00a0Modern C++ Challenge in my last\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":1496,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/03\/10\/book-review-c-concurrency-in-action\/","url_meta":{"origin":980,"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":2915,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/09\/18\/book-review-embracing-modern-c-safely\/","url_meta":{"origin":980,"position":2},"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":2868,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/11\/book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code\/","url_meta":{"origin":980,"position":3},"title":"Book Review &#8211;  Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code","author":"admin","date":"July 11, 2022","format":false,"excerpt":"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\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\/07\/Book-Cover2-233x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1278,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/02\/book-review-functional-programming-in-c\/","url_meta":{"origin":980,"position":4},"title":"Book Review: Functional Programming in C++","author":"admin","date":"December 2, 2018","format":false,"excerpt":"Title: Functional Programming in C++: How to improve your C++ programs using functional techniques Author: Ivan Cukic Publisher: Manning Publications Co. Year: 2019 This book came out recently, about a week ago. I bought it immediately, and when I started to read it, I couldn\u2019t put it down! Very informative\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":980,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/980","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=980"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/980\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}