Ooh boy. I’ve had too much of a bad experience with C++ recently to be able to read this article without having my stomach turn.
C++ is a terrible language that needs to be scrapped and rewritten (or replaced with C, because - you know - C actually works). Here are a few of the main issues I’ve had with it over the last few days while completing assignments for my CS class:
The STL is crap. There are way to many inconsistencies that you have to remember to be be able to effectively use it, and it’s difficult to determine what type you’re working with (without an IDE). If the type system is so screwed that I can’t write a simple project with Vim, it’s not good enough. Some of it is just asinine too (who the frick though streams were a good idea? Fun fact - you can’t get a file handler from an fstream - so much for a low level systems language)
C++ has too many high-level “features”. Yup, I agree with the author. C++ has a cleaner language inside struggling to get out. That language is C. Giving access to high level “features” without proper reflective programming leads to disaster and stupidly difficult debugging. Here are some of the ones that especially get to me:
I fear C++ may have got itself into a bit of a Perl-esque quandary
Hmm… I wonder why. Maybe that’s because its syntax has gone so far off the deep end (to the point that it can’t be parsed like a regular language).
To sum it up, the problem with C++ is that it wants to be a safe, high level language, while at the same time being a fast, unsafe, low level language without powerful enough language constructs to work with. Lisp is the only language that’s pulled off both being very high level and very low level at the same time (and generally, it’s done with safety as well). The only sane way to write C++ code is to write C code.
You missed the most hysterical streams feature: I/O manipulators. Streams carry state, and updating that state takes a silly amount of code:
// printf( "%10.4f\n", 1.0f );
// right align a float with 4dp, also break printing everywhere else in the program
std::cout << std::setw( 10 ) << std::right << std::fixed << std::setprecision( 4 ) << 1.0f << "\n";
Yeah great feature, like we are all gonna add a wall of setw/setfill/left/god knows what every time we want to print something.
(wow, while I was looking this up I found this gem)
Oh sheesh. I forgot about those. I’ll admit that C format strings are a bit cryptic, but i/o manipulators are unreadable (like everything else in C++).
C++ tries to hide pointers: just don’t. It trains people not to think about whether something’s been passed by reference or value, and results in too much magic. C++ is a low level language
Amen. I first encountered C++ at Google and I hated it. If the language is presented as a high-level language, it makes no sense.
It’s more acceptable once you learn C++’s purpose, which is to be a C-like language where you don’t have to create your own string class and hash table. If you use C++ and expect to work at a high-level pace and use it as a high-level language, it’ll make you miserable.
I’ve definitely met some great C++ programmers who swear by the language, but what I’ve noticed is that they mostly use it as C-plus-a-few-things and avoid the object oriented crap. They’ll use the string class and the STL collections when they suit their purposes, but they avoid friend classes and inheritance and all that nonsense. Of course, being dropped into an existing C++ codebase written by average corporate programmers is a fate that I wouldn’t wish on anyone.
It’s more acceptable once you learn C++’s purpose, which is to be a C-like language where you don’t have to create your own string class and hash table.
Statements like that are so common I’m starting to believe most programmers have not yet learnt about concepts such as libraries and code reuse. So for them, it is easier to write or switch to a new programming language than it is to address the lack of certain functionality by employing code that already solves it.
In C and C++, the lack of a package concept and/or standardized build system makes re-using code a lot tougher than in other languages. That has an effect too.
C’s lack of templates/generics make things like a generic hash table more difficult than they need to be. Incidentally, “C with templates” is IMO the best way to use C++ :).
You make a good point. I think the problem is that programming culture, at least in the corporate world, has become so fixated on gluing together off-the-shelf assets, and so averse to the old Unix philosophy of modular small programs, that features get stuffed into frameworks and languages instead of independent libraries. This leads to coupling and bad software in general, and also to the current culture of developer powerlessness and mediocrity in which you hear nonsense like “I’m not sure that Haskell is ready for production”.
There seems to be a growing awareness about these issues in the C++ community. I was reminded of Dan Saks talk from CppCon 2016 about talking to C programmers about C++: