C++ is Ugly
The LBL people have given me a weekend to learn C++. With the understanding that it was much like Java, I went in planning to learn a little new syntax and be done. If only I knew what I was getting myself into….
I should preface this by saying that if I had my way, every programming language would look exactly like Lisp. Failing that, I’ll settle for syntax that’s not to wordy and most importantly matches the underlying paradigm. This, I think, is the fundamental problem with C++: it tries to brutally force OOP on a language that was never meant to deal with objects.
Just to be clear, I’m not complaining about functionality - obviously it does everything it’s supposed to very well, or we wouldn’t still be using it. I just can’t get over what a massive kludge the language is - it’s just so ugly to read. Like, really really ugly. Like C got pitched out of the ugly tree and hit every branch on the way down.
Some specific examples: (all of these are taken from http://www.cplusplus.com/doc/tutorial/)
class CRectangle {
int width, height;
public:
CRectangle (int,int);
int area () {return (width*height);}
};
CRectangle::CRectangle (int a, int b) {
width = a;
height = b;
}
The Java programmer in me protests loudly against the public modifier; it doesn’t look anything like the rest of the language and imposes an arbitrary grouping on the way functions are organized in the class body.
Even worse, in my mind, is the scope modifier (::). It is not initially obvious that CRectangle::CRectangle (int, int) and area () are both methods of the same class. Indeed, as there is no hierarchical organization of functions underneath the parent class we have to resort to placing each function in this pseudo-namespace to remind it who it belongs to.
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
Come on, people - this is an Object Oriented Language, and streams are Objects. Why the extra syntax for writing to or reading from streams?
CVector CVector::operator+ (CVector param) {
CVector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return (temp);
}
Okay, this is actually pretty cool.
CRectangle a, *b, *c;
CRectangle * d = new CRectangle[2];
b= new CRectangle;
c= &a;
a.set_values (1,2);
b->set_values (3,4);
d->set_values (5,6);
Any language that considers -> to be a legitimate operator needs to be taken out in back and shot. Aside from giving no indication of what it actually does (the inner Scheme programmer screams “conversion!”). It’s like COBOL, but with pictures rather than words.
**Edit** Oh yeah, that’s also in C. It’s still ugly.
Again, I’ve no problem with C++ as a language. But the fact that Mr. Stroustrup bent over backwards to make it look C-like rather than making modifications where appropriate has given it a syntax capable of singing the eyeballs of the inexperienced.
Blogged with Flock
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]