C++0x, "just about everywhere"

When I started this blog I promised myself not to post rants about C++. In something as large and complex as the C++ language there is always plenty of material to rant about, and I figured I'd quickly bore myself and everyone else. To be honest, I was planning on attempting to forget about C++ altogether as a fact of life every programmer must live with and learn to love. But here I am, writing about it quite fondly.

"C++0x" is the working title for the now feature-complete upcoming ISO standard of C++, hopefully to become "C++09" this year. In any coders diary, this is a significant occasion and shouldn't go by without some pause for thought.

I'm not going to comment on the contents of the upcoming standard for a while, but if you work with C++ I highly recommend you check it out so I'll provide some links at the end.

I'm currently more interested in the development trend of the language itself. The process is fascinating. Plus, I am cooking up a proposal for a new language project based on C++ that could be an interesting angle - but that's for another day.

Significant standards

The first standard for C++ came in 1998, almost 20 years after it's conception in 1979. By 1998, C++ itself had long since 'dug in' and by many accounts the standardisation effort was a big painful undertaking. Unsurprisingly it wasn't perfect and "C++98", as it became known informally, had a spring clean in 2003 but without any significant changes an end-user would notice.

C++0x represents the first major revision of the language since it was first standardised as C++98, and looks to be another dramatic undertaking. It's a pretty bold move on many levels. It has many bright innovations and the current draft appears to be very well thought through.

I find C++0x even more remarkable when considering how it has been developed. On face value, the end product could be considered fairly impenetrable and bears more similarity to a legal contract than a working design. The C++ standardisation committee is a huge international democratic effort with nearly 200 members consisting of "corporations to fanatics". It has no owner. It does no marketing. But it appears to know that the decisions it makes through its huge, painful, diligent and slow process will effect the lives of literally millions of developers. I think it's a spectacular organisational achievement and its coordinators probably possess saint-like levels of patience :).

C++ "everywhere"

Now, in theory, you could write any application in assembler - but it doesn't scale so you'd struggle to write large, complex software with it. And you couldn't write every application in C# or Java. As interpreted, garbage-collected languages, they are just not always going to fit with your hardware or application's performance demands. C++ is in a sweet spot.

Even so, I have a love/hate relationship with C++. On one hand, I've spent many an hour teasing out holes and swearing at my compiler, but on the other I have no doubt my job would be more more difficult without it. Despite its flaws it is a language that is unique in the range of applications it can address. And because of this it's a language that's "just about everywhere".

I'm quoting Bjarne Stroustrup, from a talk he gave to the University of Waterloo last year. As the language's father and original author he may have a bias, but he has some evidence to support his statement. It's arguable that this applications list could well be cherry-picked, but I'd hazard a guess that he's likely to be more in touch with the users of C++ than most, and frankly I agree with him.

Endless growth

"Give a man enough rope and he will hang himself". There's even a book on C/C++ with the same title. As I published this post I discovered Bjarne is quoted as saying, "C++ makes it harder to shoot yourself in the foot; but when you do, it takes off the whole leg". His argument is really that the idiom is as true of C++ as it is of any powerful tool. I think this is a fair point but I think it is still a valid concern to have of popular language, particularly one that's growing.

So, given the language is about to expand even further, I spent a surprisingly enjoyable couple of hours one Saturday morning watching Bjarne talk through some new features in C++0x and comment on its development.

C++0x appears to me to not be an extension in the sense it just provides some new features. In the literal sense, this is exactly what C++0x does. But when inspected more closely, some of the features actually help clean up some of the extraneous cruft. To me, features such as initialisation lists and concepts appear to be part of a crafty expand-but-consolidate manoeuvre. If you're worried about having too much rope, then this is the best possible route the committee could have taken, so I am suitably impressed.

Subtraction

The committee have one hand tied. They simply can't subtract. It's practically impossible for them to remove features or they risk breaking people's existing code and the fallout from that could be enormous.

To be fair, the standardisation committee pursue some other options as well. They look at revising the C++ standard libraries (stl). Libraries are a far simpler way to extend a language as they are intrinsically "turn on and off-able" in a way language extensions typically are not. Opinions on the stl tend to vary, but I don't think many people would argue that they could be considerably better.

Libraries are not immune from the subtraction problem. But it's definitely an area the committee could do a lot of further good.

C++ is dead. Long live Java/C#/Python/etc

Although it's not specific to C++, the 'subtraction problem' is a rather fundamental problem with all language development - and perhaps much "live" software. Like many humans, software has a tendency to grow-up too quickly, become fat and fidgety at the peak of its powers, leading to the inevitable replacement by younger leaner contenders.

Given the inevitable growth at each revision - however well constructed the revision - how far will the life of C++ extend? In the long run, is C++ condemned to expand its way to death? This is certainly the view many people like to hold.

The death of C++ was being widely touted while I was at university in the 90s, rather conspicuously around the same time the first ISO C++ standard was being agreed. C++ was an old messy language that Java would replace, we were told. This belief extended into the course structure where no C or C++ option was offered. As a consequence I was never taught the language I've used daily ever since. And to be honest, I would not be surprised if some universities continue to do the same thing now.

Despite it all, C++ lives on and does so with relative ease. C++0x should further increase the language's lease on life. However, C++0x will not - and can not - resolve all the problems with the language. Assuming we believe perfection is possible, to do so requires subtraction, and subtraction requires an alternative approach to the standardisation committee. I have a proposal brewing on this topic, which I'll return to in a follow-up post.

Some references

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.