17

As you may have heard, the last meeting of the C++ standards committee voted to remove concepts from the next C++ standard. Of course, this will affect other features and would seem to throw the standard wide open again. If that is the case, which other features do you think should be stripped away (or added), and why?

Links:

Removal of Concepts -- Danny Kalev (on the decision to remove concepts)

Simplifying the use of Concepts -- Bjarne Stroustrup (on the problems with concepts as they look now)

The Long Pole Gets Longer -- Martin Tasker (on the impact to the schedule for C++0x if concepts have to be fixed)

The C++0x "Remove Concepts" Decision - Stroustrup on the issue on Dr. Dobbs

Trip Report: Exit Concepts, Final ISO C++ Draft in ~18 Months - Herb Sutter

Concepts Get Voted Off The C++0x Island - Jeremy Siek defending the current Concepts spec

What Happened in Frankfurt? - Doug Gregor on C++Next (on the history and removal of Concepts).

  • 14
    I want concepts to be stripped of being stripped away. :| – GManNickG Jul 20 '09 at 19:19
  • 6
    While it might be considered as subjective/argumentative (someone voted for closing) I think it is an interesting discussion (and is posted as community wiki). It might be subjective, but not the type of subjective that starts flame wars. – David Rodríguez - dribeas Jul 20 '09 at 19:28
  • 4
    *"The Concepts proposal was doomed because the committee wasn't standardizing existing practice (which is what it usually does) but instead, invented a huge, complex and controversial feature ex nihilo. History shows that features that were added in this unusual way to C++ have all failed. This was the case with exception specifications and exported templates."* I don't buy this, though. – Johannes Schaub - litb Jul 20 '09 at 19:44
  • @litb could you make that an answer so people can comment a bit more easily? I have to say that I agree (mostly) with the quote. –  Jul 20 '09 at 19:46
  • 1
    @Neil Butterworth, I agree partially too. But i don't agree with the comparison with exception specifications. Look at all the complicated and weird error messages we have today, they would go away. I didn't post as answer, because i find it's not really an answer to "what should go too", just a small opinion about that sentence :) – Johannes Schaub - litb Jul 20 '09 at 19:49
  • @litb - I think it's an apt comparison - exception specifications had a noble aim as well (quite similar to concepts, in fact: extending the power of static type checking). It's not the aim that's the problem - who wouldn't like clearer error messages? – Daniel Earwicker Jul 20 '09 at 19:56
  • What happened to export templates anyway, in C++0x? Is it deprecated, unchanged, or being more forcefully encouraged? – GManNickG Jul 20 '09 at 19:56
  • This is a community wiki post. Please stop voting to close. I will vote to reopen if the post is closed. – Randolpho Jul 20 '09 at 19:59
  • 1
    I don't understand why is this question http://stackoverflow.com/questions/1154974/c0x-will-no-longer-have-concepts-opinions was closed, but Neil's is allowed to stay open? – Steve Folly Jul 20 '09 at 20:04
  • That one was just a statement: "Concepts are gone." this one is more of a discussion about the features of C++0x in general. – GManNickG Jul 20 '09 at 20:05
  • @Steve I am asking a specific question, albeit one with more than one answer, hence the CW. The other one just said "Discuss", which is not what SO is intended for. –  Jul 20 '09 at 20:08
  • 1
    @Earwicker, i don't know the history. But it makes it difficult to believe that concepts have no existing practice. boost.type_traits and boost.concept_check and lots of others (stlfilt, adobes stuff) all show that concepts are needed and are simulated all the way. – Johannes Schaub - litb Jul 20 '09 at 20:12
  • It's true, I've often written structs to serve as the "archetype" for a type parameter, as part of a compile-time test suite for a template, though never went as far as using boost's `concept_check` in real code. But the proposed language feature went quite a long way beyond that - when reading up on it I felt a bit like I was reading about an entirely new separate language, very like reading about C++/CLI. – Daniel Earwicker Jul 20 '09 at 20:26
  • 3
    JSiek has written a touching lament to C++0x concepts: http://lambda-the-ultimate.org/node/3518. @litb - i agree with the reality of that quote - but i dislike its spirit. Whil I am no language implementer, you only have to have worked on one or two big projects to appreciate that an initial specification rarely ever does justice to the final product that eventually gets accepted. I do dislike its spirit because it suggests that we can't just have the most bad-ass C++ wizards get together and design the perfect language (without implementing the compiler first ;) – Faisal Vali Jul 21 '09 at 02:27
  • 3
    Importantly, concepts are not dead, they're delayed. Think about customer deliverables. You can hold off for 3 years until feature Z is ready or you can ship the version you have now with features A-Y pretty much cooked. Consider: auto, decltype, variadic templates, lambdas, template alias' the improved memory model etc etc. Concepts improve error messages, great, but I want to start using 'auto' when I make calls to STL members **now**! IMHO, this is best for everybody: Concepts when added will be ready, and today we get a much improved standard. – Richard Corden Jul 21 '09 at 12:10
  • I think dropping concepts was the right thing to do for now. Hopefully they'll be able to pick them up again after 0x is finalized, but in their current form, I think we're better off without them. – jalf Jul 21 '09 at 13:57
  • btw, added another link to the OP, which probably contributed strongly to the decision – jalf Jul 21 '09 at 14:09
  • 1
    I might point out this topic was a techical discussion by some of the most active and knowlegeable C++ participants on SO. It was in no way subjective or argumentative –  Jul 22 '09 at 20:51

9 Answers9

27

Of course, this will affect other features and would seem to throw the standard wide open again.

Hardly. They still want to wrap up the standard soon, which is one of the main reasons for removing concepts. Making it "wide open" to unrelated changes would just throw away everything they gained by ditching concepts.

Anyway.... Of the remaining C++0x additions, I can't think of anything else I'd want to remove. I agree with their decision regarding concepts though. Stroustrup's paper really outlined some serious problems, The current specification for concepts would admittedly simplify template error messages, but it would do so by dramatically reducing the usefulness of generic programming -- a price I'm not willing to pay.

When I first read that paper, it scared me, because I assumed it was too late in the process for making serious changes to the spec. Turns out it wasn't, and the committee was willing to take dramatic action.

But apart from this, I think C++0x is in good shape. The remaining new features all look worthwhile.

Of course, there are plenty of existing features I'd love to remove. Primarily the vector<bool> specialization. There are other popular examples of features that didn't work out (the export keyword, exception specifications), but the vector specialization is the only one of them that can't be ignored. As long as we don't try to export templates, it doesn't matter that the keyword exists (and isn't implemented by compilers), and we can just refrain from using exception specs, but every time we need a vector of bools, we're bitten by the stupid premature optimization that slipped into the current standard.

Unfortunately, it seems like they've given up on removing it. (Last I checked, it wasn't even deprecated).

Of course, plenty of old C cruft could be ditched too, but recently, I've discovered that the one change I'd really love to see is...... ditching the Iostreams library. Toss it out, and build a new STL-style I/O library based on generic programming.

The current OOP-styled Iostreams library is ugly, slow, overcomplicated and inflexible. There's too much voodoo involved in defining new streams, too few standard stream types involved, too little flexibility (the problem that made me realize how limited the library is, was that I needed to extract a float from a string. Easy to do with stringstream, but if you need to do it often, you don't want to have to copy the input string every time (as the stringstream does) -- where's the stream that works on an existing iterator range? Or a raw array, even?)

Throw IOstreams out, develop a modern replacement, and C++ will be vastly improved.

And perhaps do something about the string class as well. It works sort of ok'ish as it is now, but really, what's with the huge number of member functions? Most of them would work better, and be more general, as free functions. Too much of the standard library relies specifically on the string class, when it could in principle work with any container, or even an iterator (std::getline, I'm looking at you)

jalf
  • 243,077
  • 51
  • 345
  • 550
  • 6
    Awesome, absolutely great answer! (OK, some of that was to get over the 15-char thing) –  Jul 21 '09 at 14:06
  • 3
    I've found you can just insert 15 spaces after the first word. They get compressed down to a single space when displayed, but you get over the 15 char limit :D – jalf Jul 21 '09 at 14:07
  • 5
    Yep, iostreams are horrible - we should really get something better. In fact, I would like to see a better (and smaller) string class as well, but that is not going to happen. – Nemanja Trifunovic Jul 21 '09 at 15:25
  • 3
    Both of these (iostreams, string) are pure library concepts. This is really where something like boost can come into it's own. If worthy replacement libraries were developed there, then they may well get "standardised" (as has happened to a lot of other boost libraries). – Richard Corden Jul 21 '09 at 18:50
  • I doubt new replacement libraries would be added, no matter how good they were. They'd have to offer something significantly new, and the standard would be left with two (conflicting) string classes. But yes, they could be developed as libraries outside the standard. – jalf Jul 24 '09 at 19:17
  • Thing about iostreams and strings is that they really are good enough for almost all purposes. They're usable. It's not much worse than religiously omitting exception specifications. – David Thornley Sep 02 '09 at 13:57
  • 1
    I disagree. Iostreams are so painful they're almost useless at anything more complex than Hello World. String is *good enough*, yeah, but iostreams? It's pretty telling that this is about the only case where a significant number of C++ programmers *still* prefer the C equivalents. printf is unsafe as hell, but it's usable. – jalf Sep 02 '09 at 16:28
  • 4
    if you want a few examples of where they fail, here's a very incomplete list: cout << "hello " << "world" won't be written out atomically. Other threads might jump in after "hello" and print something out. This makes composing output in a thread-safe way pretty tricky. wifstream can't actually handle wide characters. It reads char's, and internally widens them to wchar_t. istream has some very weird ways to handle leftover whitespace (every beginner struggles with simple tasks like "wait for enter to be pressed, then read more input". – jalf Sep 02 '09 at 16:33
10

Personally, I want C++ to finally break away from C. No more pre-processor, no more header files. I basically want D, but without all the stuff that D tacks on, using the STL.

Randolpho
  • 55,384
  • 17
  • 145
  • 179
  • 1
    This is exactly how I feel. I hate the old C crap that gets in the way. – GManNickG Jul 20 '09 at 19:37
  • 2
    Amen to that. Toasting the C pre-processor ought to qualify the standards committe that does it for a Nobel peace prize. What would society do with the sudden burst of productivity? – T.E.D. Jul 20 '09 at 19:41
  • 4
    I wouldn't say I'm a macro fan, but there are a few I'd be hard-pressed to replace with any other current mechanism. –  Jul 20 '09 at 19:44
  • 9
    I like header files. – Paul Nathan Jul 20 '09 at 19:44
  • 3
    @Paul - some people pay good money to be whipped! – Daniel Earwicker Jul 20 '09 at 19:48
  • 2
    @Earwicker Then include (ha-ha) me in for a bit of flage - I like them too. –  Jul 20 '09 at 19:50
  • 4
    There are some things that make good use of preprocessor macros. I am thinking of boost::bind/boost::function and probably others... – David Rodríguez - dribeas Jul 20 '09 at 19:56
  • 1
    Okay, who's next for a bit of pun-ishment? – Daniel Earwicker Jul 20 '09 at 19:57
  • 6
    Nothing that breaks backward compatibility can be seriously considered for the new standard. There is too much existing C++ code outside that needs to work. – Nemanja Trifunovic Jul 20 '09 at 23:16
  • 14
    If you want D, use D, not C++. – Marc Mutz - mmutz Jul 21 '09 at 08:12
  • Ditching the preprocessor would be great, but replacements would have to be added. There are quite a few features that still depend on the preprocessor (the assert macro, for example). Headers are horrible. Luckily they're still planning to get around to that module system later, afaik, so who knows, perhaps one day we won't need headers. – jalf Jul 21 '09 at 13:36
  • @mmutz: the point is that I *don't* want D, because D does things stupid. It started out with a great premise: ditch the preprocessor and use a symbol table rather than requiring header files, then went ass crazy with all the changes it did. I just want C++ the way C++ is, but without forward declaration, headers, and a preprocessor. – Randolpho Jul 21 '09 at 14:22
  • @Randolpho, you can have part of your wish courtesy of Lazy C++, at www.lazycplusplus.com. – Kevin Jul 21 '09 at 15:04
  • @Kevin: Maybe, but it's a monkeypatch that hides the issue rather than fixes it. – Randolpho Jul 21 '09 at 15:36
  • You may want to see this thread about why macros are still needed in C++ http://stackoverflow.com/questions/96196/when-are-c-macros-beneficial – Motti Jul 21 '09 at 19:43
  • @Motti: I've read them all. About half are due to the deficiencies of having header files and (ironically) macros themselves. The rest are thing that you Should Not Do(tm). – Randolpho Jul 21 '09 at 20:00
  • Header files are beautiful flowers, full of light and joy and goodness. – Eric M Sep 11 '09 at 21:34
5

None, I think the rest of the draft was great - a large number of very small pieces that can be correctly implemented independently, allowing vendors to evolve toward complete support and allowing users to take a "shopping list" approach.

Quite a different situation with contracts, as they were like a whole new parallel type system and would have been very likely to have led to different compilers ending up with their own backward compatibility problems, very similar to CSS in web browsers.

Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
  • Yeah, concepts had become a really major feature touching almost every part of the standard. That made them dangerous, and of course, made it essential that they got it right the first time, or we would have risked a mess similar to CSS and other web standards. C++ could not afford that. +1 – jalf Jul 24 '09 at 19:23
5

There are two things I think should be added to C++0x, I've thought of both these myself and then found that others have suggested them before but it doesn't seem like they're going to happen.

1. Defaulting Move Constructors and Move Assignment Operators

Writing a move constructor is a manual and error prone activity, if a member is added it must be added to the move constructor and assignment operators and std::move must be used religiously. That's why I think these functions should be defaultable.

movable(movable&&) = default;
movable& operator=(movable&&) = default;

Edit (2009-10-01): Looks like this is going to happen after all.

2. Override Type Deduction for Expression Templates

Expression templates often define types that should not be used directly, a case in point is the return value of std::vector<bool> operator[](size_type n), if auto or decltype are used on this kind of object unexpected behaviour may ensue. Therefore a type should be able to say what type it should be deduced to be (or prevent deduction using = delete syntax).

Example for vector addition.

// lazy evaluation of vector addition
template<typename T, class V1, class V2>
class vector_add {
     V1& lhs_;
     V2& rhs_;
public:
     T operator[](size_t n) const
     { return lhs_[n] + rhs_[n]; }
     // If used by auto or decltype perform eager creation of vector 
     std::vector<T> operator auto() const 
     {
         if (lhs_.size() != rhs_.size()) 
             throw std::exception("Vectors aren't same size");
         std::vector<T> vec;
         vec.reserve(lhs_.size());
         for (int i = 0; i < lhs_.size(); ++i)
            vec.push_back(lhs_[i] + rhs_[i]);
         return vec;
     }
Motti
  • 110,860
  • 49
  • 189
  • 262
  • 1
    I find the second one surprising. In the example you give, what would be the problem with using `auto` to store an instance of `vector_add`? Surely this is a major application of the new `auto`, making it practical to store intermediate results from expression template systems (especially as they tend to have revoltingly huge type declarations). – Daniel Earwicker Jul 24 '09 at 20:19
  • 4
    The problem is that expression templates are designed to work within a statement which means that they probably store a reference to the two operands, if one of these is temporary it may be destroyed before the `vector_add` instance is used. – Motti Jul 25 '09 at 19:54
  • 2
    @DanielEarwicker: http://coliru.stacked-crooked.com/a/0b3f7d571659c9a8 – Mooing Duck Feb 13 '14 at 21:38
3

To me the problem is not what other features should be stripped away, but how complex will other features be after concepts have been removed. That and how much longer will it take for the rest of the features to be rephrased without concepts.

A lot of features assumed that concepts would be accepted into the language and the wording is expressed in terms of concepts. (I wonder if any proposed feature depends on concepts).

I also wonder how other libraries will evolve (think boost::type_traits) to take the niche left by concepts. Part of what concepts provided can be implemented (even if in a more cumbersome way) in terms of traits applied to the type arguments.

To me, the most important thing that concepts added to the language was an expressive formulation of compilation errors, which is nowadays one of the places where C++ is most criticized.

R.I.P. concepts.

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
  • 1
    Personally I suspect this won't be rocket science (though the result will obviously take months to review carefully). Any feature that is specified in terms of concepts can simply state the signatures of the operations it requires on types. The standard could easily retain a limited version of concepts just "on paper", purely as an aid to unambigious specification. – Daniel Earwicker Jul 20 '09 at 19:46
  • Concepts "on paper" as a tool for terse and unambiguous specification is a very good idea. – Piotr Dobrogost Jul 20 '09 at 20:05
  • From what I can tell, the only real casualty without concepts is "foreach", and that is a relatively small feature and so should be easy to fix. – Richard Corden Jul 21 '09 at 09:52
  • According to Herb Sutter's blog post, the range-based for loop was the only feature that depended on concepts, and that was fixed during the meeting. – jalf Jul 24 '09 at 19:15
2

Do whatever you want with concepts, but for god's sake keep threads and atomics, we absolutely need them. Perhaps add thread groups and support for cooperative threads a.k.a. fibers. IMO these are far more important than concepts, because everyone uses/will soon be using threads.

Giovanni Funchal
  • 8,934
  • 13
  • 61
  • 110
  • hehe, I think threads are pretty safe now. Partly because they're the only major flagship feature left, and partly because as far as I know they're pretty well integrated into the draft standard already, so there aren't really any problems surrounding them. – jalf Aug 17 '09 at 20:45
1

Strip away the pages of error messages on template code!

IIRC concepts should solve a big C++ coder problem: Human readable error messages for the STL. Its bad news that this issue isn't addressed.

just somebody
  • 18,602
  • 6
  • 51
  • 60
Maik Beckmann
  • 5,637
  • 1
  • 23
  • 18
  • 2
    That is what Concepts tried to achieve – David Rodríguez - dribeas Jul 20 '09 at 19:58
  • 2
    That's a quality of implementation issue for the compiler - nothing to do with the standard. –  Jul 20 '09 at 20:01
  • 2
    @Neil: Still, it would be nice to have a certain standard of quality applied to make the errors a bit easier to decipher. Error log filters are all well and good, but... wouldn't it be nicer if the compiler filtered them out for you in the first place? – greyfade Jul 20 '09 at 20:42
  • Ah, you young folk don't know when you are well off! The Glockenspiel compiler (cfront derived, late 80s) used to simply core dump if it came across any code it particularly disliked (which was quite a bit). This was (btiefly) the standard compiler at the training company I worked for - the paying customers were not amused. –  Jul 20 '09 at 21:04
  • @greyfade I basically agree. Some sort of "precis the message" switch would be nice. But sometimes you need the whole shebang. –  Jul 20 '09 at 21:05
1

I'd like to remove =delete.

There's already a common and accepted idiom for acheiving the same effect (declare the function in question as private). I think this feature will just generate lots of 'I used =delete to remove a base class function from my derived class, but it can still be called using a base class pointer' questions.

Not to mention confusing people between the (now) two meanings of the delete keyword.

JoeG
  • 12,994
  • 1
  • 38
  • 63
0

The un-named function / lambda function stuff makes me nervous. Function objects are perfectly good and are explicit, thus easier to read and find.

On the other hand I kinda liked concepts, though I certainly would not have used them every day.

Eric M
  • 1,027
  • 2
  • 8
  • 21
  • 1
    I don't know how the committee is proposing lambda functions, but if it's anything like C#'s, it's a very worthy addition to the language. – Pedro d'Aquino Jul 20 '09 at 19:35
  • 10
    I like lambdas. They make it easy to write shorter code, without the weird bloat you have to write today – Johannes Schaub - litb Jul 20 '09 at 19:42
  • @Pedro - it's a very similar addition, just capturing a commonly-used pattern in a succinct syntax. If the user has to give something a name just so they can refer to it once, it's a likely spot to add some sugar to the language. People who like writing out the same ugly pattern every time are free to continue doing so, of course! :) – Daniel Earwicker Jul 20 '09 at 19:42
  • Perhaps I haven't used them enough to appreciate them. But when there are blocks of code outside named methods or functions I do not see how one can, say, find them with an editor. It seems like a lot of searching. C & C++ have always required one to be explicit about code structure - block structured and everything has a name. Thus function objects. Giving something used once a name - is that really so onerous? I do not think so. My $0.02. – Eric M Jul 20 '09 at 20:03
  • You can put a block after `while (n != 0)` - does that block have a name? – Daniel Earwicker Jul 20 '09 at 20:08
  • @Earwicker If you refer to something in source code it will not be once almost for sure :) – Piotr Dobrogost Jul 20 '09 at 20:09
  • 5
    That's because you're only counting the pieces that have names and hence are referred to, instead of simply appearing nested at the one location they are needed. All programs consist of a lot of chunks of unique code, many of which it would make no sense to jump into; they only make sense in the context they are embedded in. The lack of lambdas forces the user to pull code out of context and then laboriously write the necessary plumbing to feed data in and out of it. – Daniel Earwicker Jul 20 '09 at 20:16
  • 3
    To put it another way, a while loop "refers" to the block or statement immediately following it. Wouldn't make a lot of sense for anything else to refer to it, and so there's no reason to force users to think of a name for it. – Daniel Earwicker Jul 20 '09 at 20:18
  • 5
    lambdas make a good picture together with other features. condition variables for example will be able to `c.wait([&] { return count == 0; })` This would look awfully bloated without lambdas – Johannes Schaub - litb Jul 20 '09 at 20:25
  • 1
    @hoohoo: I'd recommend trying out a functional programming language when you have the time. The flexibility that lambdas give you is rather eye-opening, and gives you new ways of approaching problems - and, even, of constructing functions. They're not to be underestimated. – greyfade Jul 20 '09 at 20:40
  • c.wait(var(count) == 1); Bloated ? – keraba Jul 21 '09 at 03:03
  • Take a look at http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions - that's how they implemented it. – shash Jul 21 '09 at 09:32
  • 1
    Lambdas are basically the one missing piece in making STL algorithms *really* shine. Having to define functors is tedious and takes up a lot of space, sometimes making a plain for loop more attractive than std::for_each. Being able to inline the functor by declaring it as a lambda finally makes for_each and similar algorithms easy to use. – jalf Jul 21 '09 at 13:31
  • @keraba, no it's not, but it's a hack. Try to call v.begin() with your notation. – Johannes Schaub - litb Jul 21 '09 at 14:46
  • 8
    I can't count how many times I've said "screw this" and written a manual loop rather than build a custom functor for std::for_each. Lambdas will be incredibly useful. – Tyler McHenry Jul 22 '09 at 21:16
  • Mostly for Earwicker: an 'if () {block}' has no name, but it is contained in a function or method that does. I commented imprecisely. I mean that: functions or methods are named blocks ie return_type function_name(args) { block }, where the block may contain other blocks. In the absence of the lambda stuff, one cannot have an uncontained block floating around... you can start at main() and trace the flow of a program by following the function calls around. If I have lambdas then I think I would get lost because they don't have names (and as I noted above, I could be wrong about this). – Eric M Sep 11 '09 at 21:30