Slashdot Mirror


Bjarne Stroustrup On Concepts, C++0x

An anonymous reader writes "Danny Kalev has an interview with Bjarne Stroustrup about the failure of concepts, the technical issues of concepts, whether the ISO committee's days are over, and whether C++ is at a dead-end. 'I don't think that concepts were doomed to fail. Also, I don't think concepts were trying to fix many things or to transform C++ into an almost new language. They were introduced to do one thing: provide direct language support to the by-far dominant use of templates: generic programming. They were intended to allow direct expression of what people already state in comments, in design documents, and in documentation. Every well-designed template is written with a notion of what is required from its arguments. For good code, those requirements are documented (think of the standard's requirements tables). That is, today most templates are designed using an informal notion of concepts.'"

30 of 346 comments (clear)

  1. Really Unfortunate Initials by eldavojohn · · Score: 4, Funny
    I enjoyed the interview but I felt the initials of the participants were really unfortunate. DK and BS? I kept reading the whole thing as:

    Donkey Kong: The specification of concepts has taken seven years. By contrast, the standardization of the entire STL took about half that time. What is so complicated about concepts?

    Bull Shit! I count the concepts work as started in 2002! I presented my first design papers in 2003! In 1994 Alex Stepanov presented a complete implementation of the STL to Andrew Koenig and me, but 2002-to-2009 and 1994-to-1998 are not comparable time lines! Alex had been working on the STL from at least 1976! ... etc.

    What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow." (phrase lifted from the interview) Wish we had more people like you out there, Stroustrup. Also, if this isn't fixed by now, I'm sorry Slashdot couldn't even get your name right in the title to this story.

    --
    My work here is dung.
    1. Re:Really Unfortunate Initials by Desler · · Score: 5, Insightful

      What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

      Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

    2. Re:Really Unfortunate Initials by Desler · · Score: 3, Insightful

      You've never seen a Python coder, have you?

      He said language maintainer, not language user. Care to quote the Python language maintainer(s) making such a claim?

    3. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 4, Informative

      Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

      Few people remember this days, but Java was positioned that way back in late 1990s. I cannot find any reference because I don't remember the exact words, but I recall Scott McNealy saying something along the lines of "Now that you have Java, why would you write in anything else"?

      Bertrand Meyer and his Eiffel programming language is another example. He isn't really stating directly that it's the best thing since sliced bread, but virtually all his papers on the matter read like aggressive advertisements, praising the virtues of Eiffel, and sniding other languages because they don't "see the light" in form of design-by-contract and command-query separation (conveniently ignoring the major flaws of Eiffel such as universal generic type covariance). He also edited Wikipedia article on Eiffel to match that, got extremely offended when other people have tweaked the article to remove self-promotion, and tried to "revoke" his GFDL'd contributions (read from here on, and check the article history, for the full story of that drama).

    4. Re:Really Unfortunate Initials by Desler · · Score: 5, Insightful

      What are those people supposed to say about their language? That it sucks? That user's shouldn't use it? None of those quotes imply anything that you are claiming. Those are just snippets telling people what the positives of using their languages is. In the case of Ruby the maintainer even says that if you are happy with Perl or Python that you shouldn't switch to Ruby. That's hardly a claim of "my language is the solution to all your problems and it's going to take over the world".

    5. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 3, Insightful

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Wait, wait, wait. You're seriously citing THAT as an example of (quoting from the GGP)

      "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

      ?

      The other examples are actually quite similar; Ruby says, in essence, "we think Ruby is good", and Java says, in essence, "Java is good". Nothing wrong with that - certainly it's not saying anything about other languages. In fact, in Ruby's case, it's explicitely said that if other languages work for you, then by all means continue using them.

      But Perl? You're even crazier there. Larry isn't even saying "Perl is good"; in fact, his quote could just as well have come from someone who does NOT like Perl but still wants to give some useful advice (advice that, one might add, is applicable to just about EVERY programming language).

      If that's your idea of "rah rah take over the world!", then you must be from Bizarro World - you're not even wrong.

    6. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 4, Insightful

      It's well designed

      I would disagree. Anonymous inner classes are clearly a hack necessitated by a lack of first-class function types. Lack of a more concise capturing mechanism (i.e. true lambdas) is crippling. There's nothing in the language to help solve, or even warn about, the brittle base class problem (@Override is one piece of the puzzle, but more are needed to solve it - see C# for a proper take on this problem, and API versioning in general). Type-erasing generics are one huge hack (I don't care about perf, but they are simply not first-class, and not fully typesafe - consider `instanceof` for a generic interface). Etc.

      and efficient - so much so that you can implement other languages in it, to speed them up significantly.

      Can you give any example of something being sped up significantly by reimplementing it in Java?

      C/C++, ASM, and Java are basically the big three that everything is built on top of. Many people would be shocked that an interpreted language could make the cut.

      I wouldn't be shocked, as Java isn't an interpreted language. JIT compiler still produces native code. And back when there was no JIT, Java was slow.

  2. Re:C++0x? by betterunixthanunix · · Score: 5, Informative

    No you need to calm down and thing about the previous designations of C and C++ standards: C++98, C99, etc. C++0x was intended to be a C++ standard released between 2000 and 2009; at this point, it looks like it is actually going to be released in 2010, and we'll all be calling it C++10.

    --
    Palm trees and 8
  3. Why not just do duck typing? by morgan_greywolf · · Score: 3, Interesting

    Templates are what Python calls 'duck typing'. ("If it looks like a duck and quacks like a duck...") Why not just do that? You could add methods for introspection and so forth...

    1. Re:Why not just do duck typing? by smallfries · · Score: 5, Informative

      I don't think that they are. There is quite a good comparison on the wiki page. The main difference that springs to mind is that duck typing in Python is dynamic (resolved at runtime), where-as the type system in C++ is static (resolved at compile-time). That makes them very different beasts.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    2. Re:Why not just do duck typing? by metamatic · · Score: 4, Insightful

      Because C++ is a statically typed language, which means that type errors are discovered at compile time.

      Well, many type errors are discovered at compile time. Unfortunately, static typing tends to have the side effect of requiring more complex code, and often has to be worked around.

      Personally, I write mostly in Java and Ruby. Java is pedantically static to a level that would make C++ blush, while Ruby is completely duck typed. I've had situations where Java's pedantic nature has caught bugs before test runs, but I've also had situations where the code was 10x as long and harder to debug because of the inflexibility. I think it's highly debatable which approach is better, and the answer probably depends on the kind of problem you're solving.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  4. Re:C++0x? by Trepidity · · Score: 4, Informative

    It's named in parallel with language-revision names like Fortran77 and C99, that use the base language plus the last two digits of their revision year. When the process started years ago, though, they didn't know what year it would finish, but expected it to be in the 200x decade, hence "0x". So, C++0x. Now that the finalization has slipped past 2009, it's C++1x. When it actually comes out, it will have a year with no 'x', like C++10 or C++11.

  5. No need to dramatize by loufoque · · Score: 4, Interesting

    I've seen a lot of people dramatize about concepts being removed from C++0x.

    Really, it's no big deal. There are alternative solutions, like some based on SFINAE -- that has now been extended to arbitrary expressions --, that provide almost the same feature set, the same quality in error messages, and are not much harder or more verbose to write or use.

    Actually, getting rid of concepts was probably the best solution for C++0x, since they were a lot of work to implement on top of not being that well polished, not integrating that well with the rest (concepts are not types, nor are they templates, they're a whole new category of things) which would probably have led to different categories of compliance to the new standard.
    This even gives a new chance to more vital features, such as polymorphic lambdas (understand lambdas were the types of the arguments is not given and which thus exhibit parametric polymorphism), to now being reconsidered.

  6. Uncluttered article (print = easy to read) by noidentity · · Score: 4, Informative

    Uncluttered article, without any extra crap and multiple pages. Printable = readable.

  7. Re:Maybe the vendors don't want C++... by beuges · · Score: 3, Informative

    Do you realise that most of the guts of Windows is actually written in C++? And that the secretary of the C++ Standards Committe, Herb Sutter, works for Microsoft?
    Are you even a C++ developer at all?

  8. Concepts aren't enough! by Stuntmonkey · · Score: 5, Funny

    Can't we just skip "concepts", and move straightaway to "meta-concepts"? After all, a "concept" is just a concept itself, so with meta-concepts we'll be able to define "concepts" recursively. Which doesn't sound like a win, until you realize then you can redefine concepts to fit your own idiosyncratic needs. Like how in my code, the first thing I always do is overload "+" to mean "*", and vice versa. I've always liked them the other way around, not sure why. Anyway, back on point: Concepts by itself is like the 4-blade razor, a lame, stupid half-measure. The real prize, the 360-dunk-off-the-free-throw-line, is 5 blades on a razor. I move we skip "concepts" and go for the big win. Those effeminate Python dorks will have no answer to this, they'll be stunned to see just how inferior they really are. Who's with me on this?

    Broader point: I'm sick and tired of these language designers not giving us enough features. For the last 20 years I've been waiting for a language that will allow me to redefine keywords. If that too much to ask? What if I don't happen to like "for", or "while", or "return"? Do you people lack vision, or competence, or both? Second thing on my must-have list is a pre-pre-processor. I'm tired of writing all these header files all the time. I want a way to generate them programmatically, at compile time. A small embedded scripting language would do fine, just make sure it has templates and operator overloading and multiple inheritance, so I can stretch my legs and get comfy with it. Come on people, start earning your paychecks and get some of this stuff done!

    1. Re:Concepts aren't enough! by shutdown+-p+now · · Score: 4, Insightful

      All that you want exists already, no need to wait 20 years - in fact, it was there already when you've started waiting! It's called Common Lisp.

      It's the only language I know of where you can use its macro facility (reader macros, to be specific) to fully implement another language with arbitrary complex syntax. In other words, a program written in any textual language can be a Common Lisp program if you insert a corresponding CL reader macro definition at the beginning of the code.

      Come to think of it, maybe the fact that it hasn't taken over the world yet has something to do with that...

  9. Re:Maybe the vendors don't want C++... by godrik · · Score: 4, Insightful

    C++ is far from dead in all piece of code that need performances. Intel released a C++ library called TBB to use multi-core architecture a few years ago. They do not believe it is dead. Parallel programming framework such as cilk stoped using C to use C++ to gain templates.

    Don't get me wrong, for most task people don't care about the performance provided by a low level language and thus don't need it. It is even harmful to use C++ if you are not going to do it properly.

  10. Re:The feature C++ REALLY needs. by MikeBabcock · · Score: 5, Insightful

    What on earth does a GUI have to do with a language? A GUI belongs in the C++ specification about as much as Java belongs in the kernel.

    Each has its place and is used when necessary and shouldn't be forced into a place it doesn't belong for convenience.

    --
    - Michael T. Babcock (Yes, I blog)
  11. Re:BIG need to dramatize by rockmuelle · · Score: 5, Interesting

    It is a big deal. The two most important things concepts were going to do was make generic programming in C++ (1) explicit and (2) accessible.

    Currently, generic programming in C++ is supported through a number of template meta-programming patterns and practices, most of which exist as Boost tribal knowledge - hail King Dave!* It is implicit in many library designs, but there is nothing enforcing it at the language level. If you're not familiar with the concepts of generic programming (pun intended), it's easy to mistake what's going on in the standard libraries as something else. This is especially true if your primary use of the STL is to have polymorphic container classes - you might just design a generic extension to another language that completely misses the point of generic programming (see Java Generics).

    At a more fundamental level, a lot of the power in generic programming comes from the specializations that are possible when you meet type requirements. Right now, there is no way, outside the documentation, to state requirements and possible specializations. Making this explicit in the language makes it clear to the library user what the requirements are and what specializations are available.

    This leads into the accessibility problem. Generic Programming using template meta-programming is difficult. To use it, you have to understand both the template system and generic programming. The former is defined in the standard, but the latter, as mentioned above, is tribal knowledge. By making generic programming explicit in the language, it immediately becomes accessible to a large number of developers who didn't have the time, patience, or fortitude (dealing with the Boost mailing list requires a large supply of this) to become proficient with template-based generic programming.

    As an analogy: consider object-oriented programming in C. Prior to (and even after) C++, lots of OO code was been developed in C. But, each object system was different and based on local best-practices. C++ (and Objective-C) took those practices and codified them into a language extension. As soon as that occurred, one method for OO was standardized. Developers no longer had to implement their own object systems and adhere to documented (but not language enforced) policies. And, with a standard set of rules around this flavor of OO, many other developers felt comfortable jumping in the the fray.

    Concepts in C++ should have had the same effect for Generic Programming in C++ that C++ had for Object Oriented Programming in C. The should have democratized generic programming and brought forth a renaissance in C++ library design. Instead, petty politics killed the most exciting change to C-like languages in years.

    -Chris

    *(Dave - I mean that in the nicest sense... you've done a great job with Boost (oh, we need to jam again, too)).

  12. Runtime vs. compile-time checking by tepples · · Score: 4, Informative

    The main difference that springs to mind is that duck typing in Python is dynamic (resolved at runtime), where-as the type system in C++ is static (resolved at compile-time).

    Compile-time checking has two purposes: enforce contracts between methods and allow for optimization. I'll cover each of these in turn:

    Dynamic languages have more overhead to dispatch a method call. But then static languages have to duplicate the template code for each type that it handles. It is disputed whether the more direct dispatch outweighs the overhead of loading the duplicated instructions into the CPU's instruction cache.

    Types of arguments to methods make up part of a contract between a method and methods that call it. It's good to have a compiler that can verify some of a contract at compile time, but the halting problem implies that not all parts of all contracts can be expressed in a way that can a machine can verify. Fans of dynamic languages claim that purpose-written unit tests can verify contracts more thoroughly than a compiler's built-in checking, but fans of static languages claim that properly done static typing writes half the unit test for you.

    1. Re:Runtime vs. compile-time checking by EvanED · · Score: 4, Informative

      It is disputed whether the more direct dispatch outweighs the overhead of loading the duplicated instructions into the CPU's instruction cache.

      Keep in mind that if you can statically determine what function is going to be called, you can potentially inline it. This is important for the stereotypical object-oriented designs where you have a lot of small functions (like getters and setters). This eliminates not just the function call overhead entirely, but will often enable other optimizations. (Of course, virtual functions make determining the function to be called hard or impossible in many cases.)

      So it's not just the increased call overhead that dynamic languages have to deal with, it's the lack of ability to perform a bunch of other optimizations as well. Given C++ templates vs. a true interpreted language, I would wager C++ templates would win virtually every time, I-cache pressure and all.

      However, not all is lost; JIT compilers start introducing a lot of the benefits from static typing back into the dynamic context once it decides to for-real compile part of the code. Once it does that, dynamic languages can pick up most of the benefits of the static language. (And my understanding is sometimes more, because the JIT compiler has some dynamic information while the static compiler has to make safe assumptions.) Of course, not all languages have true JIT compilers (e.g. Python (specifically CPython, the typical implementation) is bytecode-interpreted with no JIT compiler).

  13. Interviewer acted like an ass by Logic+and+Reason · · Score: 4, Insightful

    Kalev's questions came across as ignorant and belligerent, but Stroustrup answered all of them intelligently, thoroughly and patiently. It's good to know that there are men like Stroustrup still working hard on C++, even though I no longer do much work in it.

  14. What are they supposed to say by codegen · · Score: 4, Insightful

    They are supposed to make the claim against the area for which their language is most appropriate. Although to be fair, it is often the people who are marketing the self-help books that tend to be the most vocal advocates of a particular language. I remember picking up an early O'Reilly book on Perl in a bookstore and reading the introduction and putting it back on the shelf in disgust because of the zealousness of the advocacy in the introduction.

    I have also been down the "should not" path on several languages much to my chagrin. Fortunately, I've paid the price allowing me to spare my students the pain.

    --
    Atlas stands on the earth and carries the celestial sphere on his shoulders.
  15. The C+- Language by Anonymous Coward · · Score: 5, Funny

    The C+-* Language

    * pronounced "C, more or less."

    Unlike C++, C+- is a subject oriented language. Each C+- class instance known as a subject, holds hidden members, known as prejudices or undeclared preferences, which are impervious preferences, which are impervious to outside messages, as well as public members known as boasts or claims. The following C operators are overridden as shown:

    > better than
      < worse than
      >> much better than
      << forget it
      ! not on your life
      == comparable, other things being equal

    C+- is a strongly typed language based on stereotyping and self-righteous logic. The Boolean variables TRUE and FALSE (known as constants in less realistic languages) are supplemented with CREDIBLE and DUBIOUS, which are fuzzier than Zadeh's traditional fuzzy categories. All Booleans can be declared with the modifiers strong and weak. Weak implication is said to "preserve deniability" and was added at the request of the D.O.D. to ensure compatability with future versions of Ada. Well-formed falsehoods (WFFs) are assignment-compatible with all Booleans. What-if and why-not interactions are aided by the special conditional evenifnot X then Y.

    C+- supports information hiding and, among friend classes only, rumor sharing. Borrowing from the Eiffel lexicon, non-friend classes can be killed by arranging contracts. Note that friendships are intransitive, volatile, and non-Abelian.

    Single and multiple inheritance mechanisms are implemented with random mutations. Disinheritance rules are covered by a complex probate protocol. In addition to base, derrived, virtual, and abstract classes, C+- supports gut classes. In certian locales, polygamous derivations and bastard classes are permitted. Elsewhere, loose coupling between classes is illegal, so the marriage and divorce operators may be needed:

    marriage (MParent1, FParent1);
    // child classes can now be derrived
        sclass MySclass: public MParent1, FParent1
    // define MySclass
        sclass YourSclass: public MParent1, FParent2
    // illegitimate
        divorce (MParent1, FParent1);
        marriage (MParent1, FParent2);
        sclass YourSclass: public MParent1, FParent2
    // OK now

    Operator precedence rules can be suspended with the directive #pragma dwim, known as the "Do what I mean" pragma. ANSIfication will be firmly resisted. C+-'s slogan is "Be Your Own Standard."

    http://baetzler.de/humor/c_more_or_less.html

  16. Papering over the mold by Animats · · Score: 4, Interesting

    It's kind of sad. The C++ committee has taken the general position that the underlying defects of C++ should be papered over by making it possible to write templates that hide the problem. But the hiding never quite works; the mold always seeps through the wallpaper.

    The root of the problem is that C and C++ backed into a type system. Originally, C barely had types at all; there were ints and there were floats. Pointers and ints were almost interchangeable. Fields in structures were just offsets, and field names had to be unique across all structures. Gradually, C evolved into a strongly typed language. Sort of. "void *" was introduced as a sort of escape hatch for the type system.

    More importantly, there was never a clear distinction made between arrays and pointers. That single design decision is responsible for most of the buffer overflows in the world. We should have had syntax like

    int read(int fd, char buf[n]&, size_t n);
    to replace the old
    int read(int fd, char *buf, size_t n);

    which says nothing about the size of the array. Right there is the cause of most buffer overflows - the language doesn't properly support talking about the size of arrays.

    Part of the problem there was a major error in the original design of C++ - it didn't have "&" references. So you couldn't talk about a reference to an array; you had to use a pointer to the first element. That pointer has the type of the element, not of an array. Every time you write "char *buf" instead of "char buf[n]&", you're lying to the compiler. The cost of that lie is millions of crashes a day.

    Instead of fixing the mess underneath, C++ papered it over. Arrays were wrapped with classes in the Standard Template Library. The STL is a good thing, but it's not good enough to totally replace built-in arrays. So real-world programs remain a mixture of ambiguous built-in arrays, pointers to arrays, and STL arrays.

    Then the STL approached iteration as an extension of pointer arithmetic. For "compatibility" with C pointer arithmetic, iterators are not only unchecked, but are not explicitly bound to the collection over which they iterate. So the safety problems of C were carried over into STL arrays. This was another bad decision. Most modern languages approach iteration by providing a "do this to all that stuff" construct used for most common iteration cases. C++ does not.

    This is why I'm so critical of the C++ committee. If they'd focused on safety, instead of cool but obscure template features, software would be much better today.

    1. Re:Papering over the mold by Animats · · Score: 3, Informative

      C++ is dangerous because it needs to be. There needs to be one high level language in the world that's like juggling operating chainsaws to code in it, because of the options that gives you.

      Wrong. It's not essential that a language be unsafe to have low level constructs. Ada, Modula I/II/III, Clascal, Object Pascal, Eiffel, and other hard-compiled languages have been much safer than C++, with comparable power. You don't have to go to an interpretive environment to get safety. That's an illusion from Java, which was made interpretive because Sun wanted portability between their SPARC architecture and the competing Wintel systems.

  17. C++: even iostream is doing it wrong by tepples · · Score: 3, Insightful

    It is even harmful to use C++ if you are not going to do it properly.

    For example:

    • Improper: Hello world using <iostream>. I tried compiling and linking hello world with a recent version of MinGW (a port of GCC to Windows), and the binary was over 400 KB. Using shared libstdc++ doesn't help if I have to distribute an 800 KB DLL with every application. Nor does it help in embedded systems that don't already have libstdc++ in ROM: compiling hello world using <iostream> for devkitARM produced a binary nearly 180 KiB in size for a machine with 256 KiB RAM.
    • Proper: Hello world using <cstdio>. The same g++ versions produced a binary of size 5,120 bytes on MinGW (libc is msvcrt.dll) or 25 KB on devkitARM (libc is static Newlib with its own terminal emulator).
  18. C++0x by AP31R0N · · Score: 3, Funny

    Is that some kinda of filthy ASCII art?

    --
    Utilizing the synergization of benchmark e-solutions to pre-workaround action items!
  19. Re:C++0x? by Trepidity · · Score: 3, Insightful

    Hehe, it does seem a pretty good symbol of C++'s syntax: bits of syntax that make sense individually turning into a monstrosity when combined.