It’s pretty widely acknowledged that C++ is not a very nice language.
Some people hate that it still has pointers. Some people hate that it now has references. Some people hate that it now has pointers and references. It has just enough library support that some of the utilities are useful, yet professors can keep track of them all and specifically forbid you from using all the useful ones on programming assignments. It has nice features like templates and operator overloading, but makes them so painful to use that you almost wish it didn’t. (Did you know that the stream operators must be overloaded as stand-alone functions, not as member functions of the class? Otherwise you get bizarre, nonsensical compiler errors that can’t be fixed until you vaguely remember reading in your C++ textbook two years ago that the stream operators must be overloaded as stand-alone functions, and then dig out said book and look it up to confirm.)
In fact, it seems that there’s only one person in the world who didn’t get the memo about the uncool nature of C++, and that person happened to be sitting in front of me on the first day of my undergrad discrete math class.
At UC Davis, the first programming course for majors focuses on C, without worrying about object oriented anything. The second programming course for majors covers C++ and object oriented everything. I was also enrolled in the C++ class that term, and during the first session earlier that morning, the instructor (a hardassed security research guy) had finished his introduction to C++ by telling us that it was a horrible language.
See, he knows that C++ is uncool.
But the guy sitting in front of me in discrete math had a different opinion: he insisted to his friend in a loud voice that C++ was—well, if someone had a gun to your head and would shoot you unless you could say something positive about C++, what would you say?
Stroustrup tried his best. He came so close to incorporating object orientation into C.
He gave it the old college try.
It makes some things easier than C.
It’s better than Cobol.
He didn’t say any of these things.
He said it was beautiful.
He said “Yeah, I’ve looked at some C++ code, and man, it’s beautiful.”
He didn’t say it sarcastically, like “It’s beautiful. Yeah, man. Just beautiful.”
He said it passionately, like a hot-blooded young man swept off his feet by a beautiful and mysterious woman.
He said it as if he’d seen C++ at the masquerade, shared a flirtation, danced with C++, tangoed with C++, spun C++ around with a rose clenched in his teeth, and then when he was done he’d said “So, C++. Shall we meet again?” And C++ replied “At the next masquerade. Look for me at the rise of the full moon.”
Of course, some of us had a similar flirtation with C++ when we were young, hot-blooded, bucks who had just recently chosen the manliest major around and were feeling invincible. But a year or so of its prima donna antics convinced us to leave it. The drama C++ brings to a simple act like making sure the correct override of a derived class method gets called through a base class pointer, the hysterics around templates, the fights over accepting instances of the string class instead of pointers to char; sure, it adds spice at first, but eventually it just gets to be too much. Maybe you feel manly at first, like you’ve conquered the most desirable woman in the world, but eventually you just get tired of fighting with C++ over even the smallest things. Eventually you just want a safe, plodding, homely sort of language, like Java. Sure, it’s not too bright. You have to explain everything to it at untoward length. It lacks those spicy features like operator overloading, and it doesn’t always do things in the smartest or most efficient way. But it’s a hard worker and is biddable enough if you give it what it needs. It never does something so hotheaded as seg faulting.
At this point, I had already taken two semesters of C++ programming, one general introductory course and one data structures and algorithms course. For me, after a year, the romance with C++ was over, and I was starting to discover all the warts and moles and festering gumboils it keeps hidden under its flamenco gown. Probably the most festering of all the gumboils, at least as far as being the ugliest and most idiotic syntax I could possibly imagine to represent the concept, is the “virtual void belch() = 0” syntax for declaring pure virtual functions (“abstract methods” for Java people). Other genius syntax decisions were requiring a semicolon at the end of class and struct definitions and requiring a space between angle brackets in nested template declarations.
You also might expect a beautiful language to make it easy to write beautiful code—beautiful in the sense of shorter, simpler, easier to read, expressed at a higher level of abstraction. C++ does none of those things. If anything, it does the opposite; it’s frequently easier to write the ugliest, most godawful thing you can imagine than anything halfway decent, because the language contains no infrastructure to help you write the nicer solution. For example, I can’t even count the number of times I’ve dealt with text using some variation of reading a single character at a time, clumsily saving some number of them in an array, and examining the whole mess with a huge, ugly if-else if-else if-else if-else if-else if-else-if else-else statement. I could have taken the high road and written my own regular expression engine, but with C++, go too far and it could end up screaming at you for three hours and then storming off to stay with its lover, refusing to come back until your deadline has passed.
C++ has its uses. It’s fast. It’s better than Cobol. It supports object orientation somewhat better than C. But one thing it is not is beautiful.
Thus I fulfill my rite of passage. I have rejected C++. I pass the test, and remain a programming blogger.