<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: steve poling</title>
    <description>The latest articles on DEV Community by steve poling (@steve_poling).</description>
    <link>https://dev.to/steve_poling</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F569112%2F2015ed2b-1ea6-4828-a80f-71a5a87e8881.png</url>
      <title>DEV Community: steve poling</title>
      <link>https://dev.to/steve_poling</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/steve_poling"/>
    <language>en</language>
    <item>
      <title>C++ Just Ain't What It Used To Be</title>
      <dc:creator>steve poling</dc:creator>
      <pubDate>Thu, 28 Jan 2021 16:17:17 +0000</pubDate>
      <link>https://dev.to/steve_poling/c-just-ain-t-what-it-used-to-be-4eag</link>
      <guid>https://dev.to/steve_poling/c-just-ain-t-what-it-used-to-be-4eag</guid>
      <description>&lt;p&gt;An old man is wont to shake his cane and lament the decline of civilization's artifacts. I'm old, but I have no cane, nor is this a lament about the C++ programming language.&lt;/p&gt;

&lt;p&gt;I was fluent in the C++ language having abandoned C moments after Bjarne Stroustrup invented the new shiny. I paid off my mortgage writing C++ programs, and paid for my Saturn with a Java program before moving to .NET/C# and toiling in that vineyard for a couple decades.&lt;/p&gt;

&lt;p&gt;Retirement has brought a series of short term gigs that I've richly enjoyed. The most recent of which was an update of a legacy Windows application written in C++. &lt;/p&gt;

&lt;p&gt;As I assessed the legacy codebase these things became immediately apparent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;this was a steaming pile of you-know-what,&lt;/li&gt;
&lt;li&gt;its worst infractions were lapses into idiomatic C,&lt;/li&gt;
&lt;li&gt;it was better than I would have written at the time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The world has moved on from 80286 CPUs and many critical concerns of the 1990s are useless distractions today. Moreover, the C++ programming language is a lot different from the &lt;a href="https://www.youtube.com/watch?v=RWavTVo7D3M"&gt;Borland Turbo C++ compiler&lt;/a&gt; that Jason Turner recently reviewed.&lt;/p&gt;

&lt;p&gt;Since I returning to C++ after a long hiatus I've been watching a lot of &lt;a href="https://www.youtube.com/channel/UCxHAlbZQNFU2LgEtiqd2Maw"&gt;Jason Turner's videos&lt;/a&gt;. What's struck me has been the dramatic changes from Borland C++ to C++20. &lt;/p&gt;

&lt;p&gt;Just before I left C++ the STL and templates were a thrilling innovation. They were amazingly powerful until the slightest mistake prompted a wall of terrifying error messages to spill forth from the compiler. It was a simple matter of Pavlovian conditioning to make this programmer shy away from template meta-programming when deadlines loomed. &lt;/p&gt;

&lt;p&gt;Two decades later everything has moved in this direction. And it appears that concepts in C++20 will make templates safe for normal people by making compiler error messages comprehensible.&lt;/p&gt;

&lt;p&gt;I cringe at the thought of the hundreds of lines of code I wrote that can be readily replaced by three lines of today's standard library code.&lt;/p&gt;

&lt;p&gt;I engaged the legacy C++ codebase by writing modern C++ everywhere I had to fix something or add something new (-std=c++17). At first I distrusted "auto almost everywhere" until I realized it didn't undermine strong typing. Now I happily pass around auto variables whose type I cannot articulate, but the compiler enforces their consistent usage.&lt;/p&gt;

&lt;p&gt;Then there's lambdas. I fell in love with lambdas when I learned them in Python and rewrote all my C# loops as Linq expressions. When I started using lambdas in C++ STL algorithms, the legacy code became 10x more expressive. If I had been able to use C++20's ranged iterators, most of the legacy for loops would have been rewritten.&lt;/p&gt;

&lt;p&gt;In the 1990s I did not trust the const keyword. I was an idiot. By simply changing most declarations to "const auto" I can reason about the code much more powerfully. Of course, modern compilers flag inconsistent usage. &lt;/p&gt;

&lt;p&gt;Calling something const when I KNOW it's mutable gives rise to a flood of intentional error messages. "Oh, so that's where it's changing." This is a helpful way to get to know what a codebase is doing. I encourage temporarily injecting errors into code for this purpose.&lt;/p&gt;

&lt;p&gt;The tooling makes it easy to do the right thing and harder to do wrong things. Tool tips in modern IDEs are a godsend. The structure of modern C++ makes it easier to reason about code.&lt;/p&gt;

&lt;p&gt;What attracted me to C in the first place was "closeness to the metal" in the sense that I could look at C code and imagine the assembler the compiler would generate. But C had a big disadvantage: "if you want to cut your throat, C gladly hands you the knife." C++ brought many advantages to those who had been programming under the influence of Pascal.&lt;/p&gt;

&lt;p&gt;Happily, the improvements of modern C++ need not come at the expense of efficiency. We can code up the brightest shiny new feature and drop it into something like &lt;a href="https://godbolt.org/"&gt;Matt Godbolt's Compiler Explorer&lt;/a&gt; to see exactly what its assembler looks like. &lt;/p&gt;

&lt;p&gt;What attracts me to modern C++ today is its ability to capture my intent in such an expressive way.&lt;/p&gt;

&lt;p&gt;"You darned kids just don't appreciate how good you got it nowadays!" I said wagging my finger.&lt;/p&gt;

</description>
      <category>cpp</category>
    </item>
  </channel>
</rss>
