Modern C++ for C Programmers (2018)
Honestly I never want to write C++ again. It&#x27;s a horrible Frankenlanguage at this point. I wrote C++ for awhile at Google and Google uses a fairly subset of C++:<p>- No exceptions. Instead they had util::Status (open sourced as absl::Status [1]) and a union type util::StatusOr&lt;T&gt;. I don&#x27;t believe there&#x27;s a C++ equivalent for this yet. There&#x27;s a draft proposal for std::expected [2] but it didn&#x27;t make it into C++20. I&#x27;m not sure what the future is. After many years I truly believe exceptions are a false economy for error-handling;<p>2. Teams can&#x27;t write their own templates. This is for good reason. There&#x27;s almost certainly no good reason to do this and you&#x27;ll probably screw it up what with correctly handling rvalue references (eg perfect forwarding [3]) and the like.<p>3. No mutable reference parameters. These are really an anti-pattern and can give the caller no clue that something is modified. Worse, if you allow them you&#x27;ll find people forget to const their references so you don&#x27;t actually know if they&#x27;re modified or not. Even worse, the compiler doesn&#x27;t know either so it limits optimization opportunities.<p>It wasn&#x27;t perfect. For anyone in the know I&#x27;ll just say &quot;int&#x2F;size_t&quot; and leave it at that, as one example.<p>Here are some practical problems:<p>1. The language is incredibly complex. This makes tooling more difficult. It also means any large C++ shop will out of necessity limit the features allowed such that every shop using a different C++ dialect;<p>2. As much as we now (since C++11) have smart pointers, you&#x27;ll still find yourself using raw pointers. You then get into the issues that arise from this, primarily using pointers after their lifetimes and documenting who owns what the pointer points to;<p>3. The focus on threading primitives. I am now firmly in the camp that if you ever manually create a thread, you&#x27;ve screwed up. The potential pitfalls and errors from doing so are just massive. Most of the time you don&#x27;t need it either. You should be using higher concurrency primitives or, in a lot of cases, use a cooperative async-await model as you rarely ever need to write truly multithreaded code;<p>4. (This applies to C too) The fact that types are platform dependent mean you need to use translation layers. So the standards only say a short isn&#x27;t longer than an int and a long isn&#x27;t shorter than an int and that&#x27;s it.<p>5. Even initializing a variable is complicated [4];<p>6. std::string vs char * interfaces. Fun fact: there was a time in Chrome when every keypress on the Omnibar resulted in &gt;25,000 string copies.<p>7. The ability to use uninitialized memory.<p>8. Stack vs heap allocation is obviously useful but the complexity cost is just massive. Just look at lambda capture [5].<p>7. The learning curve for C++ is just huge and that entails a lot of useless knowledge (eg explicit constructors, default constructors, copy constructors, move constructors, copy constructors vs assignment operators).<p>Almost all the time you don&#x27;t write code for performance. You write it to work and for the next guy to know what the hell is going on and it&#x27;s this last one where I think C++ falls so short.<p>I&#x27;ve known too many self-proclaimed C++ experts who revel in the complexity of C++ and consider it a virtue. It&#x27;s like it allows them to show everyone how smart they are by using some esoteric feature or relying on some non-obvious default (eg a bit like the Javascript semi-colon ASI egoists).<p>I just never want to touch it again.<p>[1]: <a href="https:&#x2F;&#x2F;abseil.io&#x2F;docs&#x2F;cpp&#x2F;guides&#x2F;status" rel="nofollow">https:&#x2F;&#x2F;abseil.io&#x2F;docs&#x2F;cpp&#x2F;guides&#x2F;status</a><p>[2]: <a href="http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2017&#x2F;p0323r4.html" rel="nofollow">http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2017&#x2F;p032...</a><p>[3]: <a href="https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;perfect-forwarding-and-universal-references-in-c" rel="nofollow">https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;perfect-forwarding-and-un...</a><p>[4]: <a href="https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;initialization" rel="nofollow">https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;initialization</a><p>[5]: <a href="https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;lambda" rel="nofollow">https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;lambda</a>