RIP C++ concepts

So I just dis­cov­ered that Con­cepts have appar­ently been dropped from the C++0x stan­dard draft.

On the sur­face, a strange, strange deci­sion. Con­cepts was, prob­a­bly more than any­thing else, the face of C++0x. Remov­ing that is going to make a lot of peo­ple won­der “so why do we need the new stan­dard again?”

It was billed as the fea­ture that would make C++ usable for non-experts again. It was going to show C# gener­ics and their ane­mic con­straints mech­a­nism “how it should be done”. And now it’s gone. Why, and what does it mean for C++?

I liked the basic idea of Con­cepts. When I first encoun­tered the, well, con­cept, I thought, as did every­one else, “here’s the fea­ture that makes tem­plate errors com­pre­hen­si­ble! The fea­ture that makes type traits and a wide range of metapro­gram­ming tricks unnecessary!”

Then a cou­ple of things hap­pened. One is that I dis­cov­ered how many other new fea­tures are going to be included in the stan­dard. The other is that con­cepts, in their cur­rent incar­na­tion, actu­ally seemed down­right harm­ful — at best lead­ing to them sim­ply going unused, another ves­ti­gial fea­ture that no one uses, and com­pil­ers mostly ignore, like excep­tion spec­i­fi­ca­tions or the export keyword.

C++0x with­out Con­cepts — what’s left?

Many of them are just as ground­break­ing and use­ful as Con­cepts (lamb­das and rvalue ref­er­ences come to mind as obvi­ous exam­ples that are going to vastly sim­plify a lot of code. Lamb­das in par­tic­u­lar are the one miss­ing link that makes the STL really shine. Sure, we already had algo­ritms, and writ­ing func­tors to go with them was triv­ial, but it took up a lot of space. Reduc­ing even com­pli­cated loops to one-liners was great, but it always meant that a sep­a­rate class had to be defined else­where to imple­ment the required func­tor. With lan­guage sup­port for lamb­das, the func­tor can be defined inline, with no loss of efficiency.

Adding mean­ing­ful and portable Uni­code datatypes is another great step. Nei­ther char nor wchar_t were really portable before. They didn’t spec­ify a char­ac­ter set, and wchar_t didn’t even spec­ify a size. If we wanted portable Uni­code sup­port, we were screwed. With C++0x, we’re get­ting char­ac­ter types specif­i­cally for UTF-8,UTF-16 and UTF-32! About bloody time, but damn, this is going to be useful.

Even with­out Con­cepts, there’s a lot to be excited about in the upcom­ing standard.

We’re bet­ter off without

Then, within the last month or two, my atten­tion was drawn to two papers sub­mit­ted to the stan­dards com­mit­tee. One is by Bjarne Strous­trup, point­ing out some seri­ous flaws in the the cur­rent spec­i­fi­ca­tion of Con­cepts — in short, they rep­re­sented a move away from the struc­tural type sys­tem that tem­plates rep­re­sent, and which makes generic pro­gram­ming so pow­er­ful, and back to nom­i­nal, or named types. In many cases, users of a concept-supporting func­tion or class would have to explic­itly state that their own types imple­ment the required con­cepts, essen­tially rein­vent­ing the tem­plate equiv­a­lent of OOP inter­faces. I can fol­low the train of thought that led to this sit­u­a­tion. It obvi­ously hap­pened grad­u­ally, with the best of inten­tions, in an attempt to make Con­cepts as pow­er­ful as pos­si­ble. But ulti­mately, the result failed at ful­fill­ing the orig­i­nal goal, mak­ing generic pro­gram­ming eas­ier, sim­pler and cleaner, and acces­si­ble even to beginners.

Of course Strous­trup sug­gested ways to fix this prob­lem and bring Con­cepts back on track, but it seemed equally likely to an out­sider like me, that the com­mit­tee would sim­ply say “yes, that’s unfor­tu­nate, but we can’t afford more delays. We’d bet­ter stick with how Con­cepts are cur­rently defined”, which would leave us with a fun­da­men­tally bro­ken Con­cepts implementation.

It’s a tes­ta­ment to Stroustrup’s tal­ent as a lan­guage designer, and the com­mit­tee as a whole that this prob­lem was dis­cov­ered in the first place, and that the com­mit­tee was will­ing to take dra­matic action in avoid­ing the prob­lem. Acknowl­edg­ing such fun­da­men­tal flaws in a fea­ture they have all poured so much time, effort and ded­i­ca­tion into is not easy, and it would have been easy to brush off these con­cerns. But they didn’t. And I think they made the right decision.

The other doc­u­ment puts Stroustrup’s obser­va­tion into per­spec­tive — there’s a sched­ule to main­tain, and the Con­cepts spec­i­fi­ca­tion is essen­tially hold­ing up the entire stan­dard. It out­lines some fun­da­men­tal prob­lems — devel­op­ment on Concepts-GCC, the sole imple­men­ta­tion of Con­cepts, has halted, and its cur­rent state is years behind the cur­rent spec­i­fi­ca­tion, mak­ing it impos­si­ble to get real-world expe­ri­ence with the fea­ture, which is deemed nec­es­sary by the com­mit­tee to avoid another fiasco like the export key­word. It out­lines the timetable for get­ting a real-world imple­men­ta­tions up and run­ning based on each of the big com­pil­ers, and con­cludes that this would imply delay­ing the stan­dard by 18 months in the most opti­mistic case.

It fur­ther out­lines the options going for­ward, mak­ing it clear that the only way to get the stan­dard out soon is the dra­matic one — remov­ing con­cepts. Alter­na­tives exist, but they imply delays and/ some ugly surgery on the stan­dard, in one way or another decou­pling Con­cepts from the rest of the standard.

So it’s clear that includ­ing con­cepts would have some dra­matic con­se­quences on the C++0x stan­dard, most likely includ­ing a delay of two years or more. Stroustrup’s paper fur­ther con­vinced me that the cur­rent imple­men­ta­tion is actu­ally a step back­wards in some respects.

I don’t know what’s going to hap­pen to Con­cepts in the future. The basic idea was good, and hope­fully that can be res­ur­rected later, but per­haps the com­mit­tee is going to feel that they’ve wasted enough time on this fea­ture, and sim­ply decide to leave it for dead. That would be unfor­tu­nate, but still a bet­ter choice than the cur­rent draft spec­i­fi­ca­tion of the feature.

So good­bye for now, Con­cepts. Hope­fully we’ll see you again, but you sim­ply weren’t ready for prime­time, and for the moment, we’re bet­ter off with­out you.

And thank you to Strous­trup and the C++ stan­dard­iza­tion com­mit­tee for being will­ing to take tough decisions.

Edit:

Strous­trup posted a very inter­est­ing arti­cle on the back­ground for this deci­sion here

Share and Enjoy: These icons link to social book­mark­ing sites where read­ers can share and dis­cover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Technorati

Tags: , ,

Leave a Reply

Name and Email Address are required fields. Your email will not be published or shared with third parties.