N.B.: If you aren't technically oriented or just find technical issues boring, you can skip this post. You'll just be confused or bored.
My stance on C++ has been mixed the past few years; overall, however, I've hated it. However, as of late I've given it some reconsideration. I've been working on an application (I won't name what it does since it's not finished and I don't want to get your hopes up; suffice it to say that many a person will find it useful) which requires a specific library; unfortunately, said library is only available in Java or C++ (I won't name what library I'm talking about, lest I get horribly flamed; let's call it "the library"). It's proprietary, so no chance of having it ported (and yes, proprietary sucks, but I don't care; I want it to work, and the open source alternatives blow ass). Now, I irrevocably and eternally loathe Java, so that's not an option. This leaves the lesser of two evils: C++.
I was thinking, "tch, I'll just wrap the C++ code in a C wrapper and go from there." That turned out to be a lot harder than I thought it would be. So I figured I would just do it all in C++. I braced myself for what I thought was going to be a long $time_period.
Now, as part of this application I need to make a certain class (again, won't say what it does). I already had code lying around to do what I wanted; however, it was in C. It was then I decided to port it to C++. C++'s class mechanism seemed perfect for what I wanted to do, as I had always wanted to wrap up my library like that. So I set about getting to work.
One nice thing about C++ is that it makes it pretty easy to start prototyping. I usually plan my code by writing out all the prototypes and classes I'm going to need; later, I go about implementing them. Designing this way helps me think about what functions I need and how they should relate to each other.
Namespaces are somewhat of a mixed blessing; the idea of them is pretty nice; however, C++ uses the awkward :: operator for them, which makes them look incredibly ugly to use unless a using statement is used.
The STL is pretty nice in some aspects. Map is nice, as well as vector. The string class of C++, while a tad baroque, also brings many nice advantages. It certainly beats the shit out of C string handling (although in some cases C handling would be more efficient; but this is what string::c_str is for).
Of course, there's plenty of crap in the STL. In particular, generic programming from 〈functional〉 is a joke (if you use something once, you'll be horrified to learn that your code will become impossible to debug by others). auto_ptr is also a huge crock (after several redesigns, you think they'd get it right. They haven't.). Iterators also generally suck (for example, iterators becoming invalid when you delete an item). STL code is also a horrible pain to debug, a pain I wouldn't wish on my worst enemies. On the other hand, if you limit yourself to the STL features worth using, you're a lot better off.
My biggest complaint about C++ (that I've never gotten over) is that it's C with bolted-on OO features (and resulting grammar that looks equally bolted on). Even the author of C++ agrees that in C++ there's a cleaner language wanting to get out. Java is definitely not the language (despite what some people think), nor is C# (despite what others also think). Oh, it's not ocaml either :p.
So my overall opinion of C++: not totally horrible, and in some ways better than C. However, there is still plenty of improvement that can be made. Apparently D has gone a long way to improving it; I haven't tried it personally (as there isn't a decent implementation yet). Whether or not C++ will become a language of choice of mine (or perhaps replace C) remains to be seen.
Friday, February 13, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment