Excellent (anti-)C++ rant

“If you’ve allocated some memory for an object, and then you throw an exception, you don’t have that pointer anymore, and because C++ doesn’t have garbage collection you’ve just leaked memory. The only way around this is to implement garbage collection yourself; C++ weenies call this ‘RAII’ and if they’re really far down the rabbit hole they sometimes don’t even realize that it’s just them implementing shitty reference-counting garbage collection.”


Filed under Uncategorized

11 responses to “Excellent (anti-)C++ rant

  1. This one is even better and thorough:


    Die C++, die!

    • rich

      It’s a good one.

    • That link also contains some FUD, some of the same one as the other, and some additional one, e.g.:

      “C++ operator overloading has all the problems of C++ function overloading (incomprehensible overload resolution rules), and then some. For example, overloaded operators have to return their results by value – naively returning references to objects allocated with new would cause temporary objects to “leak” when code like a+b+c is evaluated. That’s because C++ doesn’t have garbage collection, since that, folks, is inefficient. Much better to have your code copy massive temporary objects and hope to have them optimized out by our friend the clever compiler. Which, of course, won’t happen any time soon.”

      Have they ever heard of implicit sharing? If you “copy” an implicitly shared class, all the compiler has to do is to increment one atomic integer (or even one regular integer if you don’t care about thread-safety of the sharing mechanism). That solves this problem nicely and elegantly.

      See also: http://doc.qt.nokia.com/4.7/implicit-sharing.html (but you can also implement implicit sharing without Qt, the QSharedData and QSharedDataPointer classes are helpful though).

      C++ forever!

  2. Greenspan

    lol. Dare I say, “haters gonna hate”?

  3. Jones

    Sigh… If you can’t handle C++, then don’t use it. Don’t look at it. Don’t touch it. Don’t involve with it.
    Aight? That simple.

  4. Bob

    lawl, what about destructors? it’s been awhile since I’ve used C++… but this seems like a case of: http://files.sharenator.com/haters_Haters_Gonna_Hate-s526x350-62877-580.jpg

  5. Hub

    We see that you probably take the best source of trolls on planet: Slashdot.

    The quote talks about RAII, but if you use “new” it is no longer RAII, unless said pointer is encapsulated in a smart pointer. In that case, once again, the memory is handled properly in case of exception.

    BTW since you talk about garbage collection, do you know why Java as a finally() clause of exception handling while C++ doesn’t?

    • Doing a finally in ISO C++ is as easy as:
      catch(…) {
      // do your cleanup
      // do your cleanup

      It can even be macro’d to avoid the copypasta:
      #define finally(x) catch(…) {x;throw;} do {x} while(false)

    • rich

      If the only two languages in the world were C++ or Java (or the only three were C++, Java and Python) as many of my colleagues believe, then I probably wouldn’t have much against C++.

      However once you’ve opened your mind by learning OCaml, Haskell, LISP, FORTH, and more, you realize that C++ is just a silly indulgence, a big waste of time and money for everyone.

      • bltxd


        15+ years programming in C/C++.
        1+ year in OCaml and still doing C++.

        C++ is overcomplicated for little benefits. And indeed learning OCaml has been a real eye-opener in that respect.

  6. That rant is just FUD. The paragraph you quote can be solved by a finally-like construct (see my comment above). Alternatively, RAII can be implemented using a non-copyable smart pointer (or a refcounted one which you just don’t copy around), then you’re not doing refcounting GC, since you never have more than one reference to count.

    Other FUD:
    * “So you can’t throw exceptions in destructors, or call any function that might throw an exception.” → Sure you can call a function which can throw, just enclose it in a try … catch(…) block.
    * “In every major compiler I’ve used, exception handling support is implemented in such a way that it slows down every function call you make.” → Uh, no, in current GCC it’s implemented using DWARF unwinding, which has zero cost for the non-exceptional case.

    Plus, several of the complaints are addressed by using Qt, e.g. the lack of reflection (you can use reflection on a QObject!), the complaints about the STL, the lack of a portable threading API (more portable than pthreads, that is; pthreads are already very portable, there’s even pthreads-w32) etc.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s