Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming IT Technology

Stroustrup on the Future of C++ 661

/ASCII writes "Bjarne Stroustrup, the father of C++, has written an essay [PDF] on the features of the upcoming C++0x standard. In his essay, he argues that new features should whenever possible go into the standard library and not into the language, but that the language needs to shave of a few rough corners to make it easier to use for novices."
This discussion has been archived. No new comments can be posted.

Stroustrup on the Future of C++

Comments Filter:
  • by Anonymous Coward on Monday July 11, 2005 @10:15AM (#13032556)
    [...] to make it easier to use for novices.
    Doesn't this qualify as blasphemy?
    • by insert cool name ( 889389 ) on Monday July 11, 2005 @10:29AM (#13032689)
      Doesn't this qualify as blasphemy?

      Not when it's God talking.
      • by Kurt Granroth ( 9052 ) on Monday July 11, 2005 @12:49PM (#13034018)
        Not when it's God talking

        Speaking of which, did anybody else notice the author description in that article?

        "Bjarne Stroustrup is the College of Engineering Professor in Computer Science at Texas A&M University"

        What!? Isn't that like saying the George Bush is a businessman from Texas? It's technically true, but completely misses the point on what matters.

        This makes even less sense when you try to find the target audience. If the person reading the article already knows who Bjarne is (by which I mean every single C++ programmer), then I could see them omitting the entire "creator of C++" description because, well, they already know... but then why have a description at all?

        If the person doesn't already know who this "Bjarne" is and they are reading the article, don't you think they'd want to know that he created the thing and therefore might have some relevant opinions on that matter?

        Very odd...

        • by Anonymous Coward on Monday July 11, 2005 @04:30PM (#13036371)
          "What!? Isn't that like saying the George Bush is a businessman from Texas? It's technically true, but completely misses the point on what matters."

          I don't know... don't most people prefer to emphasize their accomplishments and hide their failures?
    • Blasphemy? (Score:5, Funny)

      by smittyoneeach ( 243267 ) * on Monday July 11, 2005 @10:36AM (#13032743) Homepage Journal
      In no way. If you read the B.S. writings (and I recommend he favor the world with a middle initial) he is always concerned with teachability of a feature, which is pretty understandable when you consider he's an academic.
      Now, what an academic is doing having a successful programming language with real-world applications is another question...
    • I dunno - anybody knows where B.S. can swim?
    • Parent reminded me of the apocryphal objection to COBOL: "But Grace, darling, that will allow anyone to program" where the comparison is to assembly language.
  • by jurt1235 ( 834677 ) on Monday July 11, 2005 @10:17AM (#13032574) Homepage
    It is interesting to see how an abstract language like a programming language evolves through time. I would think that in a language like C++ the more userfriendlyness should be in the libraries and not in the language, so I agree with the author on this point. Putting it in the libraries makes it better backwards compatible, and distributable.
    • by orthogonal ( 588627 ) on Monday July 11, 2005 @10:46AM (#13032823) Journal
      It is interesting to see how an abstract language like a programming language evolves through time

      If you find that interesting, you're going to love Stroustrup's The Design and Evolution of C++.

      It's an almost novelistic discussion of how he made C in to C++, the various trade-offs required, and how he decided what changes to make or not make. For example, why the dot operator (".") can't be overloaded, but the parentheses can be, and why (contra Goslings Java) operator overloading is a good thing (short answer: it makes syntax match semantics).

      If you ever want, or need, to develop a large-scale, flexible and general system of anything (and what's more general than C++, a programming language used by millions to write both Object Oriented and just "better C" code?), D&E is a wealth of experience, carefully and fully explained.

      And, like a novel, it's for the most part a fun read. Grab a copy, and you'll not only understand C++ better, you'll understand why C++ is what it is, and how it got there from C.
      • by alispguru ( 72689 ) <bob,bane&me,com> on Monday July 11, 2005 @01:27PM (#13034404) Journal
        I prefer to think of that volume as "The Design Rationalization and Mutation of C++". An astounding amount of it is Stroustrup explaining why one feature or another would have been a good idea, but had to be shelved in favor of something simpler to implement, or requiring fewer keywords to change. It shows the extent to which C++'s design was political in addition to being technical (see Lambda the Ultimate Political Party [nhplace.com] for how this worked in the Lisp community).

        It's a good, informative read, though not always a fun one - I still gnash my teeth every time I read about how they settled on termination semantics for exceptions.
        • No finally() clause, that gets me every time. I understand that C++ wants to foster stack-based object creation vs. heap allocation, but dammit, a finally clause would have eliminated SO much redundancy in my code over the years...
  • by leomekenkamp ( 566309 ) on Monday July 11, 2005 @10:19AM (#13032591)
    Shaving off a 'few' rough edges to make it more easy for newbies... It's that what Sun tried to do? (hint: java)

    • ... or MS tried to do? (hint: C#)
      • by Da Fokka ( 94074 ) on Monday July 11, 2005 @11:06AM (#13032996) Homepage

        ... or MS tried to do? (hint: C#)

        So tell me, what really is wrong with C#?

        • C# is not standard. Yes I know there is a standard specification, but it's not an "industry standard" in that it's not supported widely. E.g. can I simply compile my C# applications on OS X in Xcode, or on Linux, even if I have used cross-platform libraries like wxWidgets? As an ISV, choosing C# would mean a choice to deliberately limit the available platforms we could run our software on. This doesn't make sense at a time when libs like wxWidgets make it easy to develop decent cross-platform software - the

    • by /ASCII ( 86998 ) on Monday July 11, 2005 @10:31AM (#13032706) Homepage
      If you would read the actual article, you would see that the edges Stroustroup talks about are little warts like :

      • whitespace sensitvity in templates, i.e. vector> is a syntax error, since >> is a single token.
      • Type declarating iterator variables can be a huge pain when using STL since the names are so long, i.e. the type 'vector >::const_iterator' is a bit of a mouthfull. Such variables can be guessed from the return type, so you could use a type 'auto' for this.


      Java does not remove a few warts from C++, it forces you to use a Garbage collector, OO design, type introspection, etc, etc. Those are pretty fundamental changes.
      • by leomekenkamp ( 566309 ) on Monday July 11, 2005 @10:42AM (#13032791)
        Yes, I know these are fundamental changes, that's why I put the word 'few' in between quotes.

        Point of fact stays however: c++ has an enormous learning curve. Complexity in the language is imho comparable to Latin: you can almost recognise the author by lookin at the code. That complexity is far, far less in java.

        Especially the gc makes life a lot easier for even seasoned programmers.

        And by the way: you can be almost as un-OO in java as you can be in c++. Introspection in java is mostly used in 'frameworks', like for instance the serialization API; normally you almost never use it.

        • by /ASCII ( 86998 )
          Two important points here:
          • There are lots of GCs for C++. They are not part of the language, they are implemented as libraries. Hopefully, a future version of the C++ standard will have a GC in the standard library. But never as a part of the language.
          • The point about introspection in Java is that it _always_ costs you in performance and memory/disc use. Even if you're not using it.
      • Yes it forces you to do all of the things that make you productive.

        Now getting back to C++, you are not forced to do anything except write code like the following:

        T & list::iterator::operator* () const
        {
        return current->data;
        }

        Yeah I suppose this is obvious, and simple! (NOT)

        I completely gave up on C++ about six months ago. Before that I was half in and half out. Having read BS's article I have to say I am glad I gave up on C++.

        I have talked to multiple people who regularly develop using Pyth
      • The template closing thing is an obvious, minor change.

        I'm not so sure about 'auto'. Just from the article, which admittedly is not supposed to be a list of features going into the new standard, I can't help but see problems. e.g.:

        auto my_thing = [complex stl expression];

        [some other complex expression](my_thing);

        and getting some horrible STL error on the second expression because the type of the first expression wasn't what you expected and now you have to figure out what it actually was and how to fo
    • by orthogonal ( 588627 ) on Monday July 11, 2005 @11:13AM (#13033086) Journal
      Shaving off a 'few' rough edges to make it more easy for newbies... It's that what Sun tried to do? (hint: java)

      Java's ok, but a few mistakes were made. Among the worst: over-reliance on the instanceof operator, and the need for something called a MethodNotSupported exception.

      Now think about what MethodNotSupported means in the context of Barbara Liskov's Substitution Principle:

      We've got a language that supports inheritance. Inheritance makes sense only insofar as Liskov's Principle is followed. Put simply, if class D inherits from class B, any "promises" that B made -- it's interface, both syntactically, in terms of public member names, and semantically, that the member functions really do do some particular thing -- any of those promises must also be kept by D, because we are saying, as Liskov tells us, that D is-a B.

      If I hand you an instance of D, and you plug it in place of am instance of B, anything that the B instance does, the D instance must at least do. Otherwise, how can you safely and with confidence substitute a the D in where the B used to be?

      But along comes Java, and the MethodNotSupported exception -- a method used by some of Java's core library, including, dismayingly enough, commonly used container classes. It's used so that a derived class can suddenly and at run-time throw it, telling you, "Whoops! Ha ha! Trickled you, I can't in fact really do what B promises! I claim I'm a B, but really, I'm not!"

      Now imagine you had a component stereo, and you replaced your tuner with a "better" tuner with all the same jacks as the original. You'd plug it in and expect it to do the same work as the original tuner, just with better reception or fidelity or whatever. Now what if you plugged in the new tuner to the old connections, and suddenly its display read: "Sure, I have a two-plug RCA input, but it's not actually connected to anything, so you can plug in an RCA jack but no sound will come out". That's what having a method that throws MethodNotSupport is like: the jack -- or member function name -- is there, but the implementation is not.

      D inherits ("extends") B, it says so right there on the label, but no sound comes out. With Liskov undermined, you don't really have an object oriented language at all. You don't really have true inheritance. What you have is a sham, a sham that can break down on you at run-time because an object is lying to you.

      And the upshot is that you don't see enough real object oriented programming by client Java coders. If the core library can get it that wrong, why should clients of that library bother to adhere to a standard?

      So you get lots of java code that does RTTI using instanceof and if( p instanceof Foo ) ... else if( p instanceof Bar ) ladders rather than calling p.virtualFunction(). Because coders won't take seriously OO that the language and its core libraries don't take seriously.

      • by Deadbolt ( 102078 ) on Monday July 11, 2005 @11:27AM (#13033232)
        So the language is responsible for the perversions that retarded coders put it through?

        If you use instanceof more than once every, say, 10000 lines of code, I will fight you. That's no lie. It's a sop, and we, the loyal Java programmers of the world, know it's a sop. People who don't know what they're doing can turn it into a crutch. But those of us who DO know what we're doing know that using instanceof should be an automatic hint to rethink the design.

        As for MethodNotSupportedException -- yes, it's kind of a hack. But the thing is, perfect designs don't translate to reality very well, and Java, for all its good points, isn't perfect. That exception lets you know when you're breaking an API contract -- though a List may have add() methods, if you want that List to be immutable, is it preferable to throw an exception from a mutator or remove the mutator from the subclass completely? Or should we just take add() out of the List interface? Point is, it's a hack, but it's a lot better than the alternatives. And what it DOES do very well is say, "Look, genius, you're saying two different things about this object. Figure out what you mean and then say it."

        I could read stupid C++/D/C/Ruby/whatever code and then blame the language too, you know.
        • by orthogonal ( 588627 ) on Monday July 11, 2005 @11:43AM (#13033376) Journal
          "That exception lets you know when you're breaking an API contract -- though a List may have add() methods, if you want that List to be immutable, is it preferable to throw an exception from a mutator or remove the mutator from the subclass completely? Or should we just take add() out of the List interface?"

          If those are the motivations, we should have an ImmutableList class without an add function, and derive the List with an add function from it (in C++, probably by private inheritance, that is, inheritance of implementation). Only the List class with the (working) add should publically inherit from the interface with an add function.

          Problem solved.

          "I could read stupid C++/D/C/Ruby/whatever code and then blame the language too, you know."

          Sure, sure. Don't be touchy. I code Java too, in fact I'm Sun Certified.

          What I'm saying is, you tell me you'd "fight" unnecessary uses of instanceof, and I believe you. I'm just trying to make your fight easier. The point is, if your core libraries don't take liberties, your fellow client coders will be less likely to -- or at least less likely to use the bad example ("but the core library does it, why can't I?") when a good java programmer, like you, points out the problem.
  • by The Mgt ( 221650 ) on Monday July 11, 2005 @10:19AM (#13032592)
    .. as to the pronunciation of 'C++0x'. Any suggestions ?
  • by Gopal.V ( 532678 ) on Monday July 11, 2005 @10:20AM (#13032597) Homepage Journal
    Stuff that went into Boost should be in the standard library from now on... Also anyone who has had to use g++filt will agree with me that C++ STL error messages need to look less like the dog's breakfast :)
    • There are a lot of good ideas in boost. I use them in my work all the time. But there is also a lot of junk. I would be very selective about adding any of these classes to libstdc++.

    • Stuff that went into Boost should be in the standard library from now on...

      Oh God, please, no!

      C++ desperately needs some basic functionality in its standard library: concurrency, GUI, maybe things like sockets. (Alas, by the standards committee's own admission, some of these -- particularly the GUI one -- are unlikely to happen.)

      What C++ doesn't need is for its relatively simple but useful standard library to be overwhelmed by every template freak and his brother's pet ideas, which is very much th

  • Dogma (Score:3, Interesting)

    by roman_mir ( 125474 ) on Monday July 11, 2005 @10:20AM (#13032600) Homepage Journal
    but that the language needs to shave of a few rough corners to make it easier to use for novices. - that is probably true. Analogy:

    GLICK
    Exactly! And that's what we're looking to do -
    shake these people up a bit, get them motivated.
    That's the whole point of the campaign. Mass
    attendance is at an all-time low in this country.
    And it's not like we're losing them to the
    Protestants or Baptists - people aren't practicing
    at any denomination these days. If we can sell
    them some show - let 'em know the Catholic church
    has some panache, we can win them back - even get
    some new ones. Fill them pews, people - that's the
    key. And cross-promoting - like with the cereal
    tie-in grabs the little ones as well. Hook 'em
    while they're young.
    (sits at his desk, lights smoke)

    RUFUS
    Kind of like the tobacco industry?

    GLICK
    Oh - if only we had their numbers. But we are
    aiming for the same demographic, even though mine
    is the soul-saving biz. And if I have to play a
    bit of the devil to bring them closer to the Lord,
    then I'll wear the cloven hooves and carry the
    pitch fork.


    -
    Today the battle is between Java and C++ and Java wins. Not because it's faster, because it is more convenient.

    What C++ could use from Java? Why, an option to have garbage collection for starters. Just an option, not a requirement.
    • Re:Dogma (Score:2, Insightful)

      by Misroi ( 834266 ) *
      C++ is just fine the way it is. If you want a language like java, go with c#.net

      and you can also code c++.net, which has the option to use the .net framework and the .net garbage collector.

      my personal opinion is c++ should stay exactly like it is. The more libraries the better. if you want some high level language, use c#.net. If you want a headache go with c++.net.
  • A better wheel (Score:5, Insightful)

    by Anonymous Coward on Monday July 11, 2005 @10:21AM (#13032602)
    Am I the only one who wonders why we need a successor to C or C++?

    I've sat through the past 10 years and watched things like Java and D and Objective C come, but meanwhile most serious OS level and game development continues to be in C or C++. Doesn't this demonstrate that new language are merely a distraction to developers who haven't fully exploited the current set?

    • Re:A better wheel (Score:3, Interesting)

      by Radres ( 776901 )
      Because sometimes you want to write something quickly without having to worry about managing memory, pointers, etc. If you're writing an application where every clock cycle counts, then yes, use C or C++, but in most cases you can get away with a little bit more CPU usage with the benefit of code maintainability. I suppose if you really had a section of code where minimal CPU usage was important, you could write that in C++ and import it into Java as a native interface library.
    • Re:A better wheel (Score:5, Insightful)

      by onnel ( 518399 ) on Monday July 11, 2005 @10:31AM (#13032702)
      No, it's more a signifier that different problems need different solutions. If all you have is a hammer, everything may look like a nail, but if you know c++, perl, php, java and a few others, your toolbox will contain an appropriate solution for a broad range of problems. I write my games in c++, my websites in php and my text parsing utilities in php. Java and python also serve their niches. Anyone who believes that a single language is the best solution to all of the broad range of problems faced by programmers is sorely mistaken. Onnel
    • Re:A better wheel (Score:5, Informative)

      by roard ( 661272 ) on Monday July 11, 2005 @10:46AM (#13032825) Homepage
      Objective-C was created in 1983 by Brad Cox, then used on NeXT, so it's not exactly something that came in the last ten year ;-)

      And actually drivers on the NeXT were written in Objective-C ;-)

      Anyway, it's all a problem of using the right tool for the right job. Objective-C is excellent (particularly with AppKit + InterfaceBuilder on OSX, or with GNUstep [gnustep.org]+Gorm) for creating graphical applications.

      If you need a very optimized code, you can do it in C, or C++... and still keep the rest of the app in Objective-C, as Objective-C is just a superset of C, and the Objective-C++ thingy let you mix C++ code an ObjC code in the same place...

      But as they say, early optimisation is the root of all evils :-) which is why most of the time you're much better off with a high-level dynamic language than with a low level or static language. My opinion.

    • C/C++ will always be used in the most cutting edge power-hungry programs, which generally means games. C/C++ will also always be used to write libraries and drivers and low level things. However in the current market its far far more beneficial to be able to have rapid development and alteration as well as platform independence. For most programs it doesn't matter if they use lots of memory and CPU power because system resources are much cheaper than programmer hours.
  • C++0x? (Score:3, Funny)

    by rerunn ( 181278 ) on Monday July 11, 2005 @10:21AM (#13032604)

    Perfect opportunity to come up with a decent name but nope, geekiness prevails and the best he can do is: C++0x
    • Re:C++0x? (Score:3, Informative)

      by /ASCII ( 86998 )
      Hmmm, the C standard are called C90 and C99. C++ follows this pattern as well with C++98, and the current C++0x, which on release will be renamed C++06 +- 1. Neat, consistent and predictable. Only6 you think it's geeky. Are you a marketer by any chance? ;-)
  • Names (Score:2, Informative)

    Jeez, can they make these names any more obtuse? As if C++ wasn't confusing enough for people not in the know, C++0x? I mean, little in-jokes are fun, but put them in code comments, not in the title.

    And I hate PDFs...if it had spiffy charts or images or something, it would be great...but it's just text! Opened it, saved as HTML and it was 78k.

  • by hey ( 83763 ) on Monday July 11, 2005 @10:23AM (#13032629) Journal
    ... its embarasing. Compare it to CPAN (perl) or Java. It can't do very much. I wish they could get some real functionality in there. Adding the Boost stuff is nice but. What some something like Java's SWT where you can write an entire GUI using the standard library. Now that would be an improvement for C++.

    I would be very easy to do. Just "steal" the API spec's from Java. That's what C# did. Just recode the entire Java API into some C++ .h header files. Call it the standard and let vendors code it out. Sweet!
    • You are frustrated because you misunderstand the definition of a programming langauge. Programming languages don't provide APIs. Let me quote from the Wikipedia:

      A programming language...is a standardized communication technique for expressing instructions to a computer. It is a set of syntactic and semantic rules...to precisely specify what data a computer will act upon, how these data will be stored/transmitted, and precisely what actions to take under various circumstances.

      This definition does n

  • C++0x? D! (Score:4, Interesting)

    by pdbaby ( 609052 ) on Monday July 11, 2005 @10:23AM (#13032638)
    Why do we need this? D is a beautiful, well-appointed systems programming language. It's got a gcc front-end. It's got garbage-collection if you want, custom memory management if you want. It's got embedded assembly if you want. And it's fast

    I thought we were staying with C++ because of all the code that's already written in it...
  • Too little too late? (Score:3, Interesting)

    by leandrod ( 17766 ) <l@dutras . o rg> on Monday July 11, 2005 @10:28AM (#13032679) Homepage Journal
    I still remember the 'C++ Advisor' or something the like from Unix Magazine or a similar publication who wrote his last column giving up on the language because only a language lawyer could keep up on the accretions to it. I don't remember what the guy went for, but if one is into OO C derivatives you have C# with its integrated, extensible type system from the DBMS up to other languages. Or Java, if you don't want to be torpedoed by MS' 'IP'. C++ should have been fixed a long time ago, but then AT&T wouldn't have suffered from NIHS and we'd be all using ObjC and OpenStep.
    • it's very telling that Stroussap looks at much more well-designed languages and always says he can't see any advantage over C++. It's time to move on alright, much as I enjoy the challenge and fun of dealing with C/C++ code, it's the wrong solution for 80% of what it's commonly used for....let's leave it to kernel and graphics/GUI libraries, but for heavens sake let the rest die off.
  • I really wonder how they're gonna do that. I know some compilers have tried that in the past, with some export template thingy stuff. Templates where instantiated at link time. However, AFAIK, that never really worked.

    Tristan
  • by brockbr ( 640130 ) on Monday July 11, 2005 @10:30AM (#13032699)
    Every time a cost of entry is reduced and the expected prerequisites are thrown aside, the result is a truly less capable *person*, not a more capable tool.

    Agreed - There are some things that need smoothing, but I for one am tired of dealing with people who lack a fundamental understanding of the *systems* as a whole. Examples of this are the folks coming out with CS degrees who aren't even capable of following a thought, let alone starting an actual career designing and developing software.

    For them, a tool like Java offers an entry level that is acceptable given there current capabilities - A tool geared towards THAT user (and a fine one at that).

    But C (and C++) can be leveraged by people who know the tool and *use* the tool for what it can do, even with it's high(er, intellectually) cost of entry.
  • by thammoud ( 193905 ) on Monday July 11, 2005 @10:33AM (#13032722)
    2020. Good luck getting all the stuff in. Long live open standards.
  • Features I want... (Score:5, Interesting)

    by BAILOPAN ( 694545 ) on Monday July 11, 2005 @10:35AM (#13032735) Homepage
    I program in C++ from dawn to dusk, and a few things really irk me about it:

    1. Member function pointers. Implementation dependent and messy syntax that few people even know about. Their use is limited, and they don't support delegates like C#, making them ugly to work with.

    2. The "virtual =0" syntax instead of something nice like "abstract" or "interface" is just weird. How can you set a prototype equal to 0? What's wrong with nice words?

    3. Operator new and delete were designed by someone on crack. The only way to call a constructor is with placement new, whose syntax looks like: new (var) type(). Placement delete, however, doesn't call the destructor, which must be invoked manually. Furthermore, delete can't take parameters like new. What.

    4. There is a "typeid" operator but no "typeof" operator. GCC has an extension for this, but it's not standard C++ I think.

    I'm sure there are other language constructs that have annoyed me, and if you don't read my mind and fix them, Bjarne, I will kick you in the pants!
    • by jonastullus ( 530101 ) on Monday July 11, 2005 @10:51AM (#13032854) Homepage
      1. Member function pointers. Implementation dependent and messy syntax that few people even know about. Their use is limited, and they don't support delegates like C#, making them ugly to work with.

      exactly, and

      std::for_each(content.begin(), content.end(),
      std::bind1st(std::mem_fun(&PointVisitor::operator( )), v));

      is neither typable nor easy to read AT ALL! plus, it makes my head ache!

    • No, there is no "typeof" but have you seen the proposed "typedecl" and the new uses for "auto"? Nice stuff. These are to be in the new standard. My main complaint is the need to use "typename" and "template" for disambiguating inside templates. Very confusing sometimes.
    • by CrayzyJ ( 222675 ) on Monday July 11, 2005 @10:58AM (#13032920) Homepage Journal
      > There is a "typeid" operator but no "typeof" operator.

      According to "Effective C++" - Meyers, if you need to know the type of a class, you designed your classes wrong. Take advantage of abstract classes and coercion for this.

    • by Anonymous Coward
      I don't know you bro, but care to elaborate on delete not calling destructor. That's kind of new thing to me after 10 years as C++ coder.

      And the syntax of new and delete is awesome and I like it very much. I don't have time to chat and explain why I mean it is(and suits language well) but it is-trust me on this one. And that delete operator doesn't take arguments, man thats as easy to do the other way as - I mean plain easy.

      and yes there is a proposal for typeof
    • by neil.pearce ( 53830 ) on Monday July 11, 2005 @11:19AM (#13033157) Homepage
      The "virtual =0" syntax instead of something nice like "abstract" or "interface" is just weird. How can you set a prototype equal to 0? What's wrong with nice words?

      The man himself, in "The Design and Evolution of C++" states...

      The curious =0 syntax was chosen over the obvious alternative of introducing a keyword "pure" or "abstract" because at the the I saw no chance of getting a new keyword accepted.
      Had I suggested "pure", Release 2.0 would have shipped without abstract classes. Given a choice between a nicer syntax and abstract classes, I chose abstract classes. Rather than risking delay and incurring the certain fights over "pure", I used the traditional C and C++ convention of using 0 to represent "not there". The =0 syntax fits with my view that a function body is the initializer for a function and also with the (simplistic, but usually adequate) view of the set of virtual functions being implemented as a vector of function pointers. In fact, =0 is not best implemented by putting a 0 in the vtbl. My implementation places a pointer to a function called __pure_virtual_called in the vtbl; this function can then be defined to give a reasonable run-time error.
    • by Anonymous Coward on Monday July 11, 2005 @11:29AM (#13033245)
      1. Member function pointers. Implementation dependent and messy syntax that few people even know about. Their use is limited, and they don't support delegates like C#, making them ugly to work with.

      False. Member function pointers are standardized and not implementation dependent. They do have a syntax that is unusual, however. It's unreasonable to expect C++ to support delegates "like C#" considering that C# was designed long after C++.

      2. The "virtual =0" syntax instead of something nice like "abstract" or "interface" is just weird. How can you set a prototype equal to 0? What's wrong with nice words?

      There is hesitation to introduce keywords, for fear of breaking backwards compatibility. If you program in C++ from dawn to dusk, the =0 notation should be perfectly normal to you, and not a problem in the slightest. They could have made it more descriptive, but it's certainly not a showstopper, and no C++ programmers I know even notice it anymore, as it is just a part of how things are done. Maybe it's a problem for newbies, but you're only a newbie for a short time.

      3. Operator new and delete were designed by someone on crack. The only way to call a constructor is with placement new, whose syntax looks like: new (var) type(). Placement delete, however, doesn't call the destructor, which must be invoked manually. Furthermore, delete can't take parameters like new. What. You cannot call constructors, PERIOD. Placement new is not invoking a constructor, it's evaluating a "new expression" using an allocator function that returns the address it is given, and a SIDE EFFECT of that is the invocation of the constructor. It's simply impossible to directly call a constructor in C++.

      As for "placement delete", I think you lack understanding. Users are not supposed to invoke placement delete, they are supposed to just invoke the destructor for objects created with placement new. Placement delete is only used to cleanup the memory when an exception causes the constructor to fail. And, as an obviously competant C++ programmer, you should know that if the constructor exits with an exception, the destructor is NOT invoked because the object wasn't constructed and therefore doesn't really exist. Operator new and delete are about MEMORY MANAGEMENT and not object lifetime issues. Constructor and destructors are about that. A "new expression" makes use of operator new and also invokes a constructor. You seem to have confused the "new expression" for operator new.

      4. There is a "typeid" operator but no "typeof" operator. GCC has an extension for this, but it's not standard C++ I think.

      You're correct, and you may find that we're trying to address this topic in C++0X. If you're interested, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers /2004/n1737.pdf [open-std.org]

    • by XNormal ( 8617 ) on Monday July 11, 2005 @12:27PM (#13033806) Homepage
      1. Member function pointers. Implementation dependent and messy syntax that few people even know about. Their use is limited, and they don't support delegates like C#, making them ugly to work with.

      For a full description of just how utterly brain damaged C++ member functions really are check this [codeproject.com]article.

      Riddle: What's the size of a method pointer?

      1. 4 bytes
      2. 8 bytes
      3. 12 bytes
      4. 16 bytes
      5. 20 bytes
      6. all of the above

      The correct answer is 6. It can be any of these sizes depending on the circumstances. And just imagine that with all of this mess method pointers STILL don't support something as elementary as delegates (bound method pointers) in a dependable and portable way.
    • ...is that they're already in use.

      Remember that, when the language syntax was designed, the idea was that every conforming C program would also be a conforming "C With Classes" program. Identifiers like "abstract" and "interface" were already in use as user variables, types, functions, etc.

      I think you would be pretty pissed off if the next revision of your dawn-to-disk programming language suddenly made "foo" or "i" a reserved keyword. :-)

      Time has passed and the two languages no longer fit together

  • by MarkusQ ( 450076 ) on Monday July 11, 2005 @10:39AM (#13032772) Journal

    the language needs to shave of a few rough corners

    Yo nee t b carefu whe cuttin corner; i yo cu to fa yo ca reall "f" yoursel ove goo!

    --MarkusQ

  • by Henry V .009 ( 518000 ) on Monday July 11, 2005 @10:42AM (#13032798) Journal
    I read the article and was confused by some of the code examples.

    The '=' have been replaced by '-' signs. (In Acrobat 7 on Windows anyway.) The code makes a heck of a lot more sense once you realize this.
  • ...change the name from C++ to Coo
  • by jonastullus ( 530101 ) on Monday July 11, 2005 @10:46AM (#13032819) Homepage
    if that were to happen i'd *so* be exhilerated!

    not having a way to initialize a std::vector with some values has always been one minor annoyance for me when using the stl containers!

    and about that "expert" thing: it is not by chance that c++ has become an expert-oriented language! there are SO many hidden traps and arcane details to get wrong that one can't just use c++ with intermediate skills and hope not to be punished! even the most simple mistakes can (and will) lead to segmentation faults and memory corruption!
    i am not even saying that c++ is an evil language, but it sure as hell isn't newbie-friendly!
    • not having a way to initialize a std::vector with some values...

      Just copy them into a back_insert_iterator...

      #include <iostream>
      #include <vector>
      #include <iterator>
      #include <algorithm>

      int main() {

      typedef std::vector<int> IntVector;
      IntVector intVector;

      const int values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

      std::copy(values,
      values + sizeof(values) / sizeof(int),
      std::back_insert_iterator<IntVector>(intVector));

      std::copy(intVector.begin(),
      • thx.

        i am/was quite aware that you COULD somehow get values into a vector. but i resent the necessity of the 4-6 lines of code of yours.

        wouldn't it be great to simply write:

        std::vector vec = {1,2,3,4};

        no matter whether it was pure syntactic sugar or however implemented, but this would elevate std::vectors to a built-in-status that they simply don't have today!
    • I'm not quite sure what you're looking for here -- a new vector has size 0 so it doesn't have any "values" to initialize (it does have memory reserved for values, but that's different).

      If you use the resize() function to explicitly give it a size then the optional second parameter allows you to initialize all the new values to a set value. That's standard, portable, and it works -- even on VC++ 6.0.
      • a new vector has size 0 so it doesn't have any "values" to initialize

        exactly!
        and as BS wrote in TFA, it would be quite nice to initialize vectors with more than 0 members; like so:

        std::vector vec = {1,2,3};

        this would be especially handy if the values between the braces above are not all the same (in which case one could use vector constructors default value)!
    • Aside from the std::vector<T>(n, initialValue) constructor, which fills the vector with n copies of the initialValue, you can use the boost::assign [boost.org] library. From the doc: "The purpose of this library is to make it easy to fill containers with data..."
      • A comma-separated list:

        vector<int> v;
        v += 1,2,3,4,5,6,7,8,9;

      • A parenthesis-separated list:

        map<string,int> m;
        insert( m )( "Bar", 1 )( "Foo", 2 );

      • Repeats:

        vector<int> v;
        v += 1,2,3,repeat(10,4),5,6,7,8,9;
        // v = [1,2,3,4,4

      • I never liked the comma-separated list method. The problem is that it doesn't work like it seems to work. Anyone "unsuspecting" who sees

        v += 1, 2, 3, 4, 5, 6, 7, 8, 9

        immediatly thinks

        v += (1, 2, 3, 4, 5, 6, 7, 8, 9)

        i.e. the list of those numbers is added to v. But don't try to type the second line! It will compile quite fine. But it will not do what you want, but rather only append 9 to the vector. However the "intuitiveness" of the method completely relies on that wrong intuition. The true mechanism at
  • http://linux.wku.edu/~lamonml/software/cpptruth.ht ml [wku.edu] So what is C++0x going to obfuscate now ? *ducks*
  • by Uksi ( 68751 ) on Monday July 11, 2005 @11:02AM (#13032958) Homepage
    I won't argue the relative merits of C++ to other languages. For many organizations, switching from C++ (regardless of whether it would make things easier) is often not an option, and not considered as an option. I will also not argue whether that is bad.

    The fact is, there's a huge C++ user and code base out there, and if they are going to stick with C++, there's exciting stuff coming.

    I feel that C++ is having its second coming, primarily due to developments like the boost library [boost.org] and the Modern C++ Design [moderncppdesign.com] book.

    For example, I've been using a combination of boost::function [boost.org] and boost::bind [boost.org] to make powerful, flexible callbacks like nobody's business. Finally, there's a function "pointer" that can work with both freestanding functions, member functions and function objects, and finally there's an easy way to delay calling functions and use closures, respectively. (Also see boost::lambda [boost.org]).

    Sure, almost all of this has been possible one way or the other (the flexible callback has been typically implemented via function ptr and void ptr argument, C-style), but it's very refreshing to actually have the code say what you mean: "I want to delay calling this function", or "this callback doesn't give a crap whether the function you're giving it is a member function or not".

    Then there are smart pointers [boost.org], which have easier-to-follow, clearer semantics, and can be used in STL containers and such. No more using easy-to-shoot-yourself-in-foot auto_ptr. It's been possible to write large chunks of code that have multiple "new" statements, but have no "delete" statements, all while maintaining exact control over the memory allocation.

    Of course there's more... Maybe it's stuff that LISP/Scheme programmers have been using for ages, but the key difference is I can now apply tools in production commercial C++ code, during my everyday work. I no longer sit and say: "oh, crap, I could really use a closure here." I just do it.

    A big problem is that the new features require greater understanding of the language and thus better training of the run-of-the-mill C++ developer. Many C++ developers I encounter do not have the sufficient understanding of these tools, and of the language. We should strive to educate our fellow developers, ... For Great Code!
  • Syntactic candy. (Score:5, Insightful)

    by mcc ( 14761 ) <amcclure@purdue.edu> on Monday July 11, 2005 @11:14AM (#13033100) Homepage
    This is mere unnecessary conveniences. What exactly are they giving us here? Well, if I'm reading this right, "C++0x"* will give us:
    • Some cases where you can type ; where previously {} was necessary, saving as many as two keystrokes.
    • The lexer ambiguity where a<b<c>> and a<b<c> > meant entirely different things is fixed, saving as many as one keystroke.
    • EVEN MORE "free" constructors which may or may not work quite the way you wanted them to in practice.
    • More "fancy cast" operators, which sounds nice until you remember that if there's ever a time you find yourself using the C++ "fancy cast" operators, then there is a damn good chance that it's because you're doing something unwise enough it really would be a better idea to refactor the code to make the "fancy cast" unnecessary.
    ...in the meantime the fundamental issues with C++ remain not only unresolved, but unaddressed. The template system is still not a generics system, but an ugly cut & paste macro system which can incidentally be used for generics, with some caveats. The class system is still fundamentally brittle and unfriendly to simple things such as upgrading a DLL or determining at runtime if two objects are of the same type. The syntax is still a forest of features whose features interact in ways so crazy and unpredictable it approaches Perl in its chaos; references are still gimped; the distinctions in behavior and use between static and dynamic objects remain awkward and newbie-unfriendly. The features that people obviously desire to have in the language as demonstrated by their tendency to hack them in with third-party libraries (like BOOST) are-- they tell us-- a good thing, and they tell us we should continue to hack them in with libraries (like BOOST). That's nice. You know, that would be a lot easier though if we had a macro system** capable of anything smarter than blind code cut and paste-- or at least a macro system** fundamentally designed to be used for anything at all other than generics.

    Meanwhile, it appears if I'm reading this right that the most important differences in C++0x will be changes to the standard library. Great. The STL was defined how many years ago, and it's only just in the last few years that compliant implementations have become commonplace? How many decades will it be before the "C++0x" library changes have become common in a cross-platform compatible way?

    C++ is an extremely useful language, and making an update to C++ which changes as little as possible so as to follow some kind of "if it aint broken don't fix it" principle is an idea which makes a whole lot of sense. However it seems likely to me from reading this that C++0x will offer so little significant difference from C++ as to make itself simply redundant.

    * ("C++0x". Were they specifically trying to come up with a name less convenient than "C#"? Ah well, I guess we can call it "COX" or "cocks" for short.)
    ** "Template system"
  • by putko ( 753330 ) on Monday July 11, 2005 @11:17AM (#13033137) Homepage Journal
    More powerful languages like ML, CAML and some Schemes have a module system. This allows the programmer to control the meaning of identifiers (e.g. what function they mean). E.g. what gets imported (and with what name), what gets exported.

    Often there is a separate notation for the modules -- it says what files contain the things, what's exported/imported etc.

    That's very useful for encapsulation.

    C++'s namespaces are a crappy attempt to get the benefits of a module system -- that's likely where he got the idea from.

    Hygienic macros would be a good step too.
    • You can really accomplish this with namespaces as they are currently.

      The using keyword isn't only used in using namespace std;. You can also say things like: using std::vector;. You can also make aliases to namespaces: namespace sp=boost::spirit; Separate things correctly with namespaces, and know how to use using and you'll already have this functionality.
  • by gregarican ( 694358 ) on Monday July 11, 2005 @12:23PM (#13033765) Homepage
    I know that's a relatively intangible question to quantify but I did find a survey [computerworld.com] that lists different programming languages used in the workplace. Seems as if C++ definitely isn't dying just yet. I found another seemingly google-based article [dedasys.com] on the popularity of various programming languages. Sure Java and C# are up there with PHP thrown in as well, but C++ still has lots of current uses. Seeing I am hooked on Ruby in my workplace I am one of the few according to all of these figures :-)
  • by Animats ( 122034 ) on Monday July 11, 2005 @01:05PM (#13034168) Homepage
    C++ is in deep trouble, and Strostrup is in denial about it.

    C++ is the only major language with extensive abstraction but without memory safety. All other major languages are either memory-safe or don't hide the underlying machinery. (Java, C#, VB, Perl, Python, etc. all have automatic memory management. Some use garbage collection; some use reference counts. C is unsafe, but hides nothing.) This fact is responsible for millions of program crashes every day. Most security holes in C++ code come from this problem. Java and C# were invented primarily to eliminate the safety problems of C++. The open source community has generally stayed with C, where at least you can see by examination what's going on. C++ is losing market share to Java.

    And Strostrup denies this is a problem.

    This has happened before. Last time, it was Wirth. Wirth designed Pascal, Modula, and Modula II, but refused to admit that each had serious problems. He fought external compilation in Pascal. He fought extensions to the language. He even fought compile-time arithmetic. In the end, he took Pascal from a major language to a historical footnote.

    Serious systems programming was once done in Pascal, but not in Wirth's version of it. The original Macintosh and Lisa software was written in nonstandard versions of Pascal. And much of the DOS era was built on Turbo Pascal. But proliferating nonstandard versions of Pascal caused another set of problems.

    C++ has been in decline for years. "Evans Data [evansdata.com] has found that the percentage of developers using C++ has steadily declined over the last six years--from 76 percent in the spring 1998 to 46 percent in fall 2004." Strostrup also denies that.

    The C++ committee has been taken over by template fanatics. Most of the committee's effort revolves around obscure template features that few will use, and which no responsible programming manager would allow on a mission-critical project. There's very little interest in language safety, and a vocal minority that insists language safety is undesirable or impossible.

    All is not well in the C++ world. Claming otherwise is irresponsible.

  • by Mingco ( 883841 ) on Monday July 11, 2005 @01:55PM (#13034707)
    The perfect balance of ease of use and richness of features for C++ is defined thusly:

    If any novice is able to pick up Bjarne Stroustrups' The C++ Language and beat him within an inch of his life... but no more, then the book is perfectly balanced between ease of use and richness of features.

    As it currently stands, I believe that every second or third novice would easily be able to beat Bjarne to a messy, bloody pulp almost as ugly as the code his language engenders.

  • It's far too late (Score:4, Insightful)

    by pammon ( 831694 ) on Monday July 11, 2005 @03:12PM (#13035549)
    "If you think C++ is not overly complicated, just what is a protected abstract virtual base pure virtual private destructor and when was the last time you needed one?" -Tom Cargill

    The largest problem with C++ is its complexity. It is not just too complicated, it is *unmanageably complicated.* Some of the symptoms are:

    • The STL has inexplicable omissions. For example, there's no portable way to seed the built-in PRNG in the random_shuffle algorithm, rendering it useless.
    • Guruhood isn't good enough. Consider the seemingly simple task of creating a stack that works correctly with exceptions. It's extraordinarily difficult [www.gotw.ca] even for a guru.
    • Language features interact in nonintuitive ways, producing a combinatorial explosion. For example, if you overload a function in a class, you don't have to use the scope resolution operator, and if you override a function, you don't have to use it either - but if you do both, you DO have to use the scope resolution operator or else you get a compile error!
    Insofar as the new C++ standard adds stuff, instead of simplifying, this will only get worse. Since it's unreasonable to expect a new standard to remove features, the problem is unfixable. The result will be that programmers carve out their separate comfort zones, compiler vendors will not implement all features, and the monolithic C++ language will fragment into a Venn diagram of sublanguages. More so than today.

It is easier to write an incorrect program than understand a correct one.

Working...