So I just discovered that Concepts have apparently been dropped from the C++0x standard draft.
On the surface, a strange, strange decision. Concepts was, probably more than anything else, the face of C++0x. Removing that is going to make a lot of people wonder “so why do we need the new standard again?”
It was billed as the feature that would make C++ usable for non-experts again. It was going to show C# generics and their anemic constraints mechanism “how it should be done”. And now it’s gone. Why, and what does it mean for C++?
I liked the basic idea of Concepts. When I first encountered the, well, concept, I thought, as did everyone else, “here’s the feature that makes template errors comprehensible! The feature that makes type traits and a wide range of metaprogramming tricks unnecessary!”
Then a couple of things happened. One is that I discovered how many other new features are going to be included in the standard. The other is that concepts, in their current incarnation, actually seemed downright harmful — at best leading to them simply going unused, another vestigial feature that no one uses, and compilers mostly ignore, like exception specifications or the export keyword.
C++0x without Concepts — what’s left?
Many of them are just as groundbreaking and useful as Concepts (lambdas and rvalue references come to mind as obvious examples that are going to vastly simplify a lot of code. Lambdas in particular are the one missing link that makes the STL really shine. Sure, we already had algoritms, and writing functors to go with them was trivial, but it took up a lot of space. Reducing even complicated loops to one-liners was great, but it always meant that a separate class had to be defined elsewhere to implement the required functor. With language support for lambdas, the functor can be defined inline, with no loss of efficiency.
Adding meaningful and portable Unicode datatypes is another great step. Neither char nor wchar_t were really portable before. They didn’t specify a character set, and wchar_t didn’t even specify a size. If we wanted portable Unicode support, we were screwed. With C++0x, we’re getting character types specifically for UTF-8,UTF-16 and UTF-32! About bloody time, but damn, this is going to be useful.
Even without Concepts, there’s a lot to be excited about in the upcoming standard.
We’re better off without
Then, within the last month or two, my attention was drawn to two papers submitted to the standards committee. One is by Bjarne Stroustrup, pointing out some serious flaws in the the current specification of Concepts — in short, they represented a move away from the structural type system that templates represent, and which makes generic programming so powerful, and back to nominal, or named types. In many cases, users of a concept-supporting function or class would have to explicitly state that their own types implement the required concepts, essentially reinventing the template equivalent of OOP interfaces. I can follow the train of thought that led to this situation. It obviously happened gradually, with the best of intentions, in an attempt to make Concepts as powerful as possible. But ultimately, the result failed at fulfilling the original goal, making generic programming easier, simpler and cleaner, and accessible even to beginners.
Of course Stroustrup suggested ways to fix this problem and bring Concepts back on track, but it seemed equally likely to an outsider like me, that the committee would simply say “yes, that’s unfortunate, but we can’t afford more delays. We’d better stick with how Concepts are currently defined”, which would leave us with a fundamentally broken Concepts implementation.
It’s a testament to Stroustrup’s talent as a language designer, and the committee as a whole that this problem was discovered in the first place, and that the committee was willing to take dramatic action in avoiding the problem. Acknowledging such fundamental flaws in a feature they have all poured so much time, effort and dedication into is not easy, and it would have been easy to brush off these concerns. But they didn’t. And I think they made the right decision.
The other document puts Stroustrup’s observation into perspective — there’s a schedule to maintain, and the Concepts specification is essentially holding up the entire standard. It outlines some fundamental problems — development on Concepts-GCC, the sole implementation of Concepts, has halted, and its current state is years behind the current specification, making it impossible to get real-world experience with the feature, which is deemed necessary by the committee to avoid another fiasco like the export keyword. It outlines the timetable for getting a real-world implementations up and running based on each of the big compilers, and concludes that this would imply delaying the standard by 18 months in the most optimistic case.
It further outlines the options going forward, making it clear that the only way to get the standard out soon is the dramatic one — removing concepts. Alternatives exist, but they imply delays and/ some ugly surgery on the standard, in one way or another decoupling Concepts from the rest of the standard.
So it’s clear that including concepts would have some dramatic consequences on the C++0x standard, most likely including a delay of two years or more. Stroustrup’s paper further convinced me that the current implementation is actually a step backwards in some respects.
I don’t know what’s going to happen to Concepts in the future. The basic idea was good, and hopefully that can be resurrected later, but perhaps the committee is going to feel that they’ve wasted enough time on this feature, and simply decide to leave it for dead. That would be unfortunate, but still a better choice than the current draft specification of the feature.
So goodbye for now, Concepts. Hopefully we’ll see you again, but you simply weren’t ready for primetime, and for the moment, we’re better off without you.
And thank you to Stroustrup and the C++ standardization committee for being willing to take tough decisions.
Edit:
Stroustrup posted a very interesting article on the background for this decision here
Tags: c++, c++-concepts, standards




