Yay, it’s been so long since an uninformed C++ rant.

You may start by reading The Tailor, off of Planet GNOME.

Back? Good. Let’s deconstruct the points :) (Quotes are abridged and not direct quotes because I don’t feel like doing the copy-editing required)

  • Methods should be virtual by default so inheritance works. Well, inheritance at run-time, since inheritance still works just fine. To be honest this is probably one other thing that could have been different between class and struct, is class having all methods be virtual while you need to specify it with struct, so that you can still write simple classes with little to no overhead, such as QColor for instance. Then again, you could actually spend the 5 minutes it takes to understand non-virtual functions (hey wait, we already know how non-virtual functions work! :) and move on with your life. Also, this is snark’s most frustrating issue with C++… I don’t know if he’s referring to the same language I am but there’s about a half-million things more annoying than virtual in C++.
  • You need to have virtual base destructors in classes with virtual methods otherwise Bad Things Happen with no warning. Except that there is a warning. Fair argument though, I remember even Qt wasn’t immune when the warning was first introduced (or turned on with -Wall) by g++.
  • It’s annoying to use multiple inheritance because you have to be really careful. Then don’t use multiple inheritance, just like GTK+ and Java don’t use it.
  • Conversion constructors are annoying because they enable a type of bug, which the C++ guys thoughfully included a keyword for to avoid automatic conversion. If this kind of bug really trips you up, don’t use conversion constructors at all. Hey, less code to write!
  • C++ lets me do other unsafe things. True. So does C, Python, Perl, Ruby, and etc. etc. etc. Are we really supposed to pine for languages that put you in a straightjacket? If you don’t like features which are potentially unsafe, then don’t use features which are potentially unsafe.
  • Don’t respond that the language isn’t at fault because that proves you’re drinking the Kool-Aid No language is without fault, but it hardly seems sporting to say that C++ is bad because it gives you more options. If you want a more restrictive language then use Java or C#.

Or to put it another way, I don’t like spicy foods. At all. But you don’t see me blogging about how spicy food is horrible, OOHHHHH NOOOO HOW DO YOU EATZ SPICY FOOD????, etc. The reason I don’t is because I know that many people enjoy spicy food, and because I DON’T HAVE TO EAT IT IF I DON’T WANT TO.

On the same note here, most of these points against C++ are things that other programmers actually desire. I like implicit conversions in some cases (although I’d rather have an implicit keyword than explicit). I certainly like having the option to have simple classes that don’t necessarily have to have a vtable, even if that means I need to remember to make my methods and destructors virtual.

Worse yet, this is a rant with no solution. C++ can’t change now, and there are plenty of popular languages out there where this list of complaints don’t apply. So why the rant on C++ when you could be writing your Vala application? Or to bring back the tailor analogy, if you could tell that the suit didn’t fit when you put it on, why did you buy it anyways, when there were other perfectly good suits available, and other men fit into your poor-fitting suit just fine?

I suspect that snark has never actually used C++ for anything substantial. Or if he did, I’m very shocked that “templates” didn’t make his list at all…