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.
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?
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.
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.
I am Richard W.M. Jones, a computer programmer. I have strong opinions on how we write software, about Reason and the scientific method. Consequently I am an atheist [To nutcases: Please stop emailing me about this, I'm not interested in your views on it] By day I work for Red Hat on all things to do with virtualization. I am a "citizen of the world".
My motto is "often wrong". I don't mind being wrong (I'm often wrong), and I don't mind changing my mind.
This blog is not affiliated or endorsed by Red Hat and all views are entirely my own.
This one is even better and thorough:
http://yosefk.com/c++fqa/
Die C++, die!
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!
lol. Dare I say, “haters gonna hate”?
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.
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
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
throw;
}
// do your cleanup
It can even be macro’d to avoid the copypasta:
#define finally(x) catch(…) {x;throw;} do {x} while(false)
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.
Agreed.
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.
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.