It’s really surprising that a language I was using 20 years ago is now my preferred choice for a large set of problems today.
Early on, I really liked C++ for certain problems, but there were downsides. I’d almost always take it over C; if used intelligently, it’s just as fast, plus I get some benefits. The problems though were:
- lack of libraries
- memory corruption risk (and the toughness of these to debug)
- memory leaks
For a time Java seemed like the ideal solution for a certain sweet spot of problems in that the above problems largely went away. Yet today, I’m not having these problems with C++! And I get some advantages too (let’s discuss the advantages in a future blog post). As to the above issues:
We now have a reasonable number of libraries for C++. The STL exist which gives a bare minimum (wasn’t there originally). More importantly, boost exists. Boost is a great set of libraries. Thanks to everyone who has worked on that project, it is very useful. Could there be more libraries? Sure. But we have a good basic set now.
What’s really amazing to me is how having good libraries has changed C++ programming. In the early days, lack of standard containers and such really meant a lot of C-style pointer manipulation and writing of data structures one’s self. These days, that is unusual, and even when necessary is often done with smart pointer classes. I rarely find stray pointer problems in C++ code these days for these reasons.
Likewise, memory leaks are a rare thing too. With auto_ptr and other abstractions, it is pretty hard to fail to free something. Sure, it’s possible, but I can leak memory in Java too by leaving a reference accidentally.
One thing I dislike about C++ is that to me, there is a fair amount of bloat. It’s not a simple language. However there is a good solution to that: don’t use things. I try to keep C++ I write simple and not get too fancy with language esoterica. A good example (not even that exotic) is avoiding multiple inheritance.
-
dmerr posted this