1. 0
  1.  

  2. 5

    It’s probably more illuminating to link directly to what makes up the substance here: http://cpp-lang.io/30-years-of-cpp-bjarne-stroustrup/

    Though the snippet on the side of the story link is worth a bit of an eye-roll: “C++ is my favourite garbage collected language because it generates so little garbage.”

    Let’s be generous and assume this has always been true. (And let’s avoid the cynical interpretation of C++ code itself being garbage.) If it’s always been the case that C++ generates so little garbage, then one only has to look at the reams of C++ code from the inital 20 years (again, being generous) and it’s obvious how difficult is has been to actually make it true in practice. It’s remarkably simple to write bad C++ code that leaks memory.

    The quote should really end this way: “…because it generates so little garbage if you write code according to how the language best works.”

    When you add that little part, you see this is true of pretty much any language. I’ve writen Python servers that ran extended periods of time without leaking memory because I took care to understand how Python resource management basically works. I do the same with C, Java, Common Lisp, OCaml, and pretty much any other programming language I use. By and large, if you’re careful and mindful of the runtime semantics, you can write pretty resource friendly code.

    I believe Bjarne is correct about this, though: “A problem that has plagued C++ forever: Poor teaching and poor understanding of C++ even among its practitioners.” I suspect there is so much bad C++ code out there because it was viewed as an extension to C when it started. To write good C++, you need much different practices than when writing good C.

    But being an extension to C is C++’s legacy and to suggest otherwise is disingenuous. I work on a compiler that is written in C++. It is not great C++ by today’s standards but that’s because large portions of it are over 20 years old. When it started, there was no (sufficiently portable) STL and it has its own versions of all that stuff. It’s total legacy and converting it to make use of all the good things in C++11 (and yes, I do consider C++11 to be pretty good) isn’t a high priority.

    I think C++11 is on a good track and I’d seriously consider it for some projects now. But pithy remarks about how awesome it is that ignores the history really grate me.

    1. 2

      I suspect there is so much bad C++ code out there because it was viewed as an extension to C when it started. To write good C++, you need much different practices than when writing good C. But being an extension to C is C++’s legacy and to suggest otherwise is disingenuous.

      It’s not clear to me that even today Stroustrup is willing to give up the claim that not only is C++ a useful language on its own, but that it’s also “a better C”. See for example here (pdf), a paper from 2007 where he uses that phrasing (bottom of the 2nd column on the first page). Since it’s a historical paper it’s possible that he’s just saying that in the historical sense, that C++ grew out of an attempt to make a better C, but the way it’s phrased it sounds a lot like that’s still the current intent, too.