Slashdot Mirror


Interviews: Ask Bjarne Stroustrup About Programming and C++

In addition to being the creator of C++, Bjarne Stroustrup is a Managing Director in the technology division of Morgan Stanley, a Visiting Professor in Computer Science at Columbia University, and a Distinguished Research Professor in Computer Science at Texas A&M University. Bjarne has written a number of books and was elected a member of the National Academy of Engineering. He will be doing a live Google + Q & A within the C++ community on August 20th, 2014 at 12:30pm EST, but has agreed to answer your questions first. As usual, ask as many as you'd like, but please, one per post.

53 of 427 comments (clear)

  1. Cutting features and old syntax? by Katatsumuri · · Score: 5, Interesting

    Sometimes well-established languages keep adding new features and syntactic constructs until most developers are not even aware of all the possibilities, and use maybe 20% in their usual daily work. The old features and syntax are kept around for compatibility and to keep the old guard content, even if cutting them would lead to faster compilation, more elegant language and less confusion.

    This may be part of the reason for the constant introduction of new trendy languages with radically simplified syntax and libraries... Which then follow the same pattern. Few languages are introducing new paradigms, many are trying to be a "better" C++, Java, LISP, JavaScript or Perl.

    Do you think this cycle is inevitable, or could it be a good idea to sometimes clean up the syntax and the obscure features in new specification versions, to keep the established languages more competitive?

    1. Re:Cutting features and old syntax? by Wootery · · Score: 2

      Reminds me of of a blog-post I stumbled across a while ago: Heat Death Of Programming Languages

      Other than a select few (C and Scheme spring to mind), programming languages get more and more bloated and incoherent over time. We certainly see this in C++, which is probably the 'best' example of the ugliness that arises through backward-compatibility. There are 4 different languages in C++ now: C++ proper, the preprocessor, the template system, and the compile-time-friendly subset.

      I suspect the D language may be growing too big for its own good. They're much less concerned with backward-compatibility, which I suspect helps with the ugliness problem, but doesn't help with, say, high-barrier-of-entry-to-reimplement, or high barrier until you're able to read real-world D code.

    2. Re:Cutting features and old syntax? by david_thornley · · Score: 2

      Overloading is useful in general, and very useful when combined with templates. Templates produce code that is identical but varies in data types. Without operator overloading, it's awkward to use complex numbers, and really awkward to use them with a template that should work on numerical data types.

      The confusion I've seen with them is in code that nobody in my shop would approve in a code review. Stroustrup historically hasn't been averse to language features that are useful when used properly and confusing when used badly.

      My top-of-the-head cruft nomination is C-style casts. Too easy to slip in, and too hard to pick up with grep.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:Cutting features and old syntax? by david_thornley · · Score: 2

      What is the compile-time-friendly subset?

      The preprocessor should not be used for things that affect code, like constants or function-like macros. Those should be const declarations and templates, respectively. Its primary remaining use is conditional compilation. That hardly counts as a language.

      It's unfortunate that the template system isn't closer to normal C++ (in Common Lisp, the macro, which does more or less what templates do, is written using normal Common Lisp), but it's not that bad.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    4. Re:Cutting features and old syntax? by serviscope_minor · · Score: 2

      That's an interesting take on things.

      The C standards people have resisted adding much to the language. This is good, but it's been a long time since I've reached for C for a new project. The main reason is that that the language is quite primitive and does very little automatically. For those reasons it won't go, but there's little reason to use it in new projects.

      And LISP always did everything anyway but personally I like the last 60 years of parsing theory and find it much easier for the compiler to parse things for me rather than me having to write out an AST by hand. I think many people agree. I love the idea of a programmable compiler, ESPECIALLY when you can program it in the same language you write in (looking at *YOU*, C++), but it's still LISP.

      The thing is it's only worth giving up the nice things for the bad syntax when there's a compelling advantage in new features. Other languages must either bolt these features on (e.g. C++ from C), or new languages replace old ones.

      LISP being the eternal thing it is never needs replacing, but it's never quite as easy to do the latest thing as the latest purpose designed languages.

      --
      SJW n. One who posts facts.
    5. Re:Cutting features and old syntax? by Wootery · · Score: 2

      What is the compile-time-friendly subset?

      constexpr. The subset was grown considerably in C++14.

      Its primary remaining use is conditional compilation. That hardly counts as a language.

      Well, no, it does count as its own language, because... it is. If you grant that the preprocessor is, at least. It's clearly separated from the C++ 'core' language, and it's something non-trivial that a C++ programmer needs to know about. Much like the preprocessor.

      There are plenty of neat tricks to be had with the template system that aren't really just conditional compilation. Type traits, static-asserts, Boost.Function and Boost.Bind spring to mind.

  2. Is the complexity of C++ a practical joke? by Anonymous Coward · · Score: 5, Interesting

    C++ is one of the most complex, inscrutable computer languages ever created. When I read about C++11, I was surprised that it layered more complexity and inscrutability on top of what was already there (like the weird lambda syntax). I wonder if C++ has become an over-the-top example of how not to do a programming language. Is that by intent, or did it just happen? In future versions of the language, will any cosmetic changes be made to create a more understandable language that doesn't overload a small set of symbols and keywords, so that normal programmers have a chance to figure out the language? The language seems to have reached the point that C++ gurus design it for other C++ gurus, and everyone else ignores it. C++ was once the up and coming language of choice, but it has become so difficult that programmers have considered it damage and routed around it. Are you comfortable with this fate for C++, as a niche language for insiders, or do you want to use your influence to rehabilitate the language so that more programmers will use it?

    1. Re:Is the complexity of C++ a practical joke? by UnknownSoldier · · Score: 2, Insightful

      This needs to be modded +10.

      C++ has become a clusterfuck of engineering.

      Some of the most painful moments of my life were working on a professional C++ compiler. Almost everyone uses the EDG front end to minimize the pain of parsing C++ into an AST.

    2. Re:Is the complexity of C++ a practical joke? by narcc · · Score: 5, Funny
    3. Re:Is the complexity of C++ a practical joke? by just_another_sean · · Score: 5, Insightful

      A practical joke? Are you joking? C++ is not designed so that every feature must be learned and used. It's complexity derives from the fact that it supports OOP, functional programming, generic programming and I'm sure others that Bjarne would happily describe to you and the reasoning behind supporting features being included in the language. Those that are confused by C++'s complexity are doing it wrong. As with Perl it's OK to use only what you're comfortable with, no one is going to make fun of you for not using advanced features and if you like you can keep a C++ program pretty basic.

      But it supports all these features to give people what they need to get their jobs done. Lambdas looked a little strange to me at first too but as I studied the examples in Bjarne's book they became clear and I think they are quite expressive, easy to use and worth looking into, especially when you combine them with the types and algorithms in the STL.

      Look, I'm a Bjarne fanboy, have been since I started programming in the 90's so maybe my bias is showing through but I never thought I'd come to an article about C++ on /. and find the only comments above a 3 were people whining about how complex a programming language is. Programming is complex, system's programming doubly so and C++ is designed to help reduce that complexity, while at the same time remaining resource efficient, when it's used correctly. If it's too hot to handle for you there is always Visual Basic.

      --
      Creationist Textbook Stickers Declared Unconstitutional by CowboyNeal
    4. Re:Is the complexity of C++ a practical joke? by Katatsumuri · · Score: 4, Insightful

      it's OK to use only what you're comfortable with

      ...until you have to read, debug, maintain and extend someone else's code.

    5. Re:Is the complexity of C++ a practical joke? by Immerman · · Score: 5, Insightful

      And? Life is a learning experience, so break out the reference manuals and learn something new. Unless you've been thrown in way over your head it's unlikely you'll encounter more than one or two new methodologies in any given codebase, and it'll probably be pretty glaringly obvious when you run into a language feature you don't understand.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    6. Re:Is the complexity of C++ a practical joke? by smaddox · · Score: 4, Informative

      C# pioneered lambda's.

      Whaaaaaat? C# was created in 1999/2000. Lisp, which was based on lambda calculus, was first specified in 1958.

    7. Re:Is the complexity of C++ a practical joke? by kthreadd · · Score: 5, Funny

      C# pioneered lambda's.

      (get (off) (my lawn))

    8. Re:Is the complexity of C++ a practical joke? by mark-t · · Score: 2

      In my experience, most corporations where extending or maintaining code that another person has written, coding styles are generally adopted so that the code is uniform. Adoption of such styles does not, in general, limit the expressive capability of the language, it just means that when you write code, you will be writing it in a way that other people will be able to read and maintain. Of course, this is not a specific issue for C++... it is equally applicable to all programming languages, and the real-world problems which arise in this regard are generally reflective of poor programming skill, not a poorly designed programming language.

    9. Re:Is the complexity of C++ a practical joke? by dentin · · Score: 4, Insightful

      This is a very good set of observations, and I also feel that C++ has become a 'niche language for insiders'. The syntax is difficult; it's remarkably easy to shoot yourself in the foot in unobvious ways; and porting can be problematic, as no two compilers compile the same code the same way. Trivial mistakes such as pointer aliasing are often compiled -silently and without error-, producing different results at different optimization levels, and -this is considered normal-. Over the years, you learn these things and you figure out which things to avoid, but for new people coming into the language, it's a huge barrier to entry.

      If the goal is to really get a lot more programmers to use it, the base syntax almost certainly needs to be improved. Rather than providing some obscure syntax to do some obscure library feature, make it easy to do simple things and make the language as idiotproof as possible. Make compilers either strictly produce well defined output as per the spec, or throw an error. Do -something- to improve template syntax.

      Pretty much all of the new features I've seen in the C++11 spec are niche features, things used by high-end library writers with 20 years of experience to do complicated library things. That's good, libraries are important. But libraries will not translate into users if normal users cannot use them, and libraries will not translate into users if the language itself is the bulk of the learning curve.

      --
      Alter Aeon Multiclass MUD - http://www.alteraeon.com
    10. Re:Is the complexity of C++ a practical joke? by Tailhook · · Score: 2

      C# pioneered lambda's.

      Ridicule of this has not been sufficient.

      Your geek cred has been zeroed. Please turn in your membership card and leave the premises.

      Before you go, please note that JavaScript, almost 10 years older than C#, has had lambdas from day one, and I don't believe any other language that has done more to expose the common programmer to lambdas. Eich took some if his design inspiration from Scheme, in which lambdas are central. Scheme, a LISP dialect, goes back to the mid seventies, perhaps before you were born.

      C# is a fine Microsoft language, but it had nothing to do with pioneering lambda.

      And the index you cite is a laugh. It had Apple's brand new Swift language floating around in the type 10 last month, gone this month. Search engine query frequency is not a terribly meaningful measure. All it means is that those interested in a given language have done a lot of searches, and that fluctuates with events such as press releases.

      Over here is a little more comprehensive study of programming language popularity. As you can see, C/C++ give up nothing to C#. Not a damn thing.

      --
      Maw! Fire up the karma burner!
    11. Re:Is the complexity of C++ a practical joke? by david_thornley · · Score: 2

      Look, people are going to write crap code in any language. If you've got to figure out exactly what that yo-yo was trying to do, a few quick manual references aren't going to be much of an additional burden.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Is the complexity of C++ a practical joke? by Garen · · Score: 2

      They do use it for Intellisense though, because C++ code is so difficult to process that Microsoft couldn't manage to re-use their own (presumably it'd be too much work to re-architect).

      Which means that there are essentially only two truly robust, re-usable C++ front-ends in the world: Clang and EDG. This is bad for everyone, because it hurts portability.

      (So I totally emphasize with the OP's comments. I wish there were some way to version the language, so that we wouldn't have to be saddled with backwards compatibiliy cruft for eternity.)

  3. On the evolution of C++ by stox · · Score: 5, Interesting

    How do you feel about the evolution of C++ since it was first implemented with Cfront? What began as a pretty straightforward language has been expanded to significant complexity. Has this evolution been positive, or has it been an attempt to make the language apply to too many possible applications?

    --
    "To those who are overly cautious, everything is impossible. "
  4. Re:Do you think the H1B system is a joke? by Richard+Dick+Head · · Score: 3, Interesting

    This question is a little US-centric. Let me try to iteravely improve on this...

    From your perspective, how is the globalization of commerce and specifically programming affecting you and those you know? Are the new high level scripting tools available to programmers since C++ became popular pushing the profession towards a more "commoditized" state, where people are easily replaceable and where the related skills and specialization eventually offer no better benefits and compensation than other less skilled professions?

  5. Favourite programming language by Bugamn · · Score: 5, Interesting

    What is your favourite programming language that isn't C++ (or C)?

  6. Do you ever feel bad? by slashdice · · Score: 3, Interesting

    Maybe the premise of this question is wrong... but I seem to recall reading somewhere that you hate C but built C++ on top of it because it was popular. Is that true and if so, do you ever feel bad about the bait and switch?

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  7. also: by slashdice · · Score: 3, Insightful

    Has everyone responsible for the std::vector<bool> tragedy been kicked in the nuts until they are no longer at risk of reproducing?

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  8. Regrets by Anonymous Coward · · Score: 5, Interesting

    What do you regret most in C++ and how would you like to change it?

  9. Replacement for iostream by tepples · · Score: 5, Interesting

    The general consensus as I understand it is that the <iostream> wing of the C++ standard library is hairy, convoluted, time inefficient, and space inefficient in implementation. What's the better solution? <cstdio>? Is Boost.Format, as shutdown -p now suggested, any good?

  10. Future of C++ Standard Library by DaphneDiane · · Score: 3, Interesting

    One of the recent concerns raised with C++ compared to other popular languages is the breadth of the standard library. I know that the C++ standard committee was looking at adding a C++ transformed version of Cairo to the standard. And of course their is boost. What else do you see coming to address the perceived API shortcomings?

  11. Designing a Language and not a Compiler by dasacc22 · · Score: 2

    With so many new languages writing a spec and then a standard compiler to conform to the spec, I'm curious how you feel about writing a spec and not a compiler.

    How do you think this compares to other efforts? Do you enjoy this aspect or do you occasionally get your hands dirty with a particular compiler source? etc.

  12. Hour of Code by Orestesx · · Score: 4, Interesting

    What is your opinion of the the "Hour of Code" as promoted by CSEdWeek? Does it trivialize computer science education?

  13. ABI by gbjbaanb · · Score: 5, Interesting

    Do you think that one thing holding C++ back is the lack of a standarized binary interface?

    Currently if I want to make a module that can be consumed by others (whether than is others using a different language, or a different C++ compiler, or even just to use a pre-built module without sources) I have to export everything as C and use its (de-facto if nothing else) binary standard.

    I think an ABI for C++ would increase its "real world" attractiveness considerably with little, if any, overhead. Do you agree, or are there issues around this that make it a significant challenge (apart from vendor adoption of course).

  14. diversity? by slashdice · · Score: 5, Funny

    Workforce diversity is a big issue these days. What steps has the c++ working group taken to increase the numbers of female and minority contributors? C++ (perhaps unfairly, due to the popularity) is often criticized in feminist circles for being a patriarchal programming language. Will you be taking steps to address those concerns?

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  15. AI writing code? by Katatsumuri · · Score: 2, Interesting

    Do you think AI will start replacing junior programmers in the foreseeable future, similar to car drivers and call center operators?

    1. Re:AI writing code? by Marginal+Coward · · Score: 2

      Do you think AI will start replacing junior programmers in the foreseeable future, similar to car drivers and call center operators?

      Why ask Dr. Stroustrup and wait for an answer? Siri could tell you now...

  16. Boost ASIO by Rob+Riggs · · Score: 2

    When will Boost ASIO make in into the standard library? C++ really needs something of this magnitude for networking and asynchronous event handling. I have not heard much on N3360 since it was proposed.

    --
    the growth in cynicism and rebellion has not been without cause
  17. Darl McBride says SCO owns C++ by DickBreath · · Score: 2

    How do you feel about the fact that Darl McBride said that SCO owns C++?

    Source 1
    Source 2
    Source 3
    Source 4

    --

    I'll see your senator, and I'll raise you two judges.
  18. new and delete; viral disposability by tepples · · Score: 2

    Why doesn't C++ have in language support for memory allocation?

    C++ has the new and delete operators, whose low-level operation a class can customize. Could you clarify what you're asking for?

    If you don't add it C# and Java with their GC awfulness will continue to eat C++'s lunch.

    The problem with tracing garbage collection as implemented in Java, C#, and the like is that it tends to break the Resource Acquisition Is Initialization (RAII) idiom seen in C++, where an object's destructor is responsible for freeing non-memory resources held by the object, and the language supports calling this destructor automatically in many cases. Instead, GC languages have what I call "viral disposability": a conventional name for an explicit destructor method that an object's owner must remember to call, and anything holding a disposable object must also be disposable.

  19. C++ is an over bloated monster by Jay+Maynard · · Score: 4, Insightful

    I learned C++ the hard way: by hacking on a million-LOC program. It's taught me to loathe the language. It's big, complex, and incomprehensible. I once spent three days chasing a bug through a twisty little maze of templates, all different. I routinely struggle with the implications of static vs. not, member variables vs. globals vs. statics, functions that are part of a class vs. those that aren't... Getting code to even compile is often an exercise in trying something, running the build process, then trying something else, lather, rinse, repeat. It's left me frustrated enough to want to drive to College Station and scream at the walls.

    All of this has left me wishing for the days of C, in which I'm quite fluent.

    Nevertheless, the world seems (perhaps overly) enamored of C++, and I'm probably going to have to deal with it. How do I learn to at least tolerate it, if not like it, instead of actively hating it?

    --
    Disinfect the GNU General Public Virus!
  20. How do you feel about the haters? by BenSchuarmer · · Score: 4, Interesting

    The comments and questions here look overwhelmingly negative. On the other hand, all of this passion only exists because people are using C++.

    1. Re:How do you feel about the haters? by DickBreath · · Score: 2

      > . . . all of this passion only exists because people are using ${SOMETHING}.

      I feel passionate about SCO (in a strongly negative way), but not because they are important, popular, or their products widely used. I feel passionate about Clojure (in a positive way) despite that it is not presently one of the top programming languages. How many people use something can be irrelevant to the legitimate reasons people feel passionately about it.

      --

      I'll see your senator, and I'll raise you two judges.
  21. Templates all over again by Marginal+Coward · · Score: 3, Interesting

    I'm a fan of C++ overall, but it seems to me that C++ templates are a bit of a disaster. They're so complex that I doubt that anybody but you and P. J. Plauger *fully* understands them. Also, when they're actually used, they often result in bloated, slow code - as I recently experienced when stepping through some STL string functions. Further, they bring on a lot of portability issues, evidently due to the difficulty that even the compiler folks have had in understanding and implementing them. Therefore, many programmers minimize their use of templates, both in their own code and in their use of templated library code.

    Compared to the complexity of C++ templates, the C macro preprocessor provides a rudimentary form of templating via its very simple and powerful paradigm of text substitution. I've had some success implementing a limited form of generic (type independent) programming in C using just the C preprocessor. I've had much less success doing generic programming via C++ templates.

    If you had templates to do all over again, what would you do differently? Was all the complexity of C++ templates (e.g. "partial specialization") really necessary to achieve its goals? Were the goals maybe too ambitious?

    1. Re:Templates all over again by angel'o'sphere · · Score: 2

      Sigh ...
      Idiocy all around ...
      How can a template end up,in slow bloated code if it only is a template, hence the word, for something you would have to write EXACTLY the same way by hand?
      So magically your hand written code would be less bloated, how so?, and less slow, how so?
      Sorry, such claims are nonsense ... they absolutely make no sense.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  22. Re:Multiple Return Types? by tepples · · Score: 2
    One question per post please.

    When is C++ going to natively support multiple return types?

    You refer to the struct or tuple hacks. PHP and Python use a tuple hack similar to C++'s to return multiple values. Perhaps what you really want is readable syntax for assignment of multiple variables from a std::tuple. And now my own question for Bjarne: When are we getting that?

  23. Given that by maroberts · · Score: 2

    C++ is more or less a superset of C (give or take a few minor issues), why has regular C continued to thrive?

    --

    Donte Alistair Anderson Roberts - hi son!
    Karma: Chameleon

  24. Which feature would you add to C++? by jonwil · · Score: 3, Interesting

    If you could add one feature to C++ (either the language or the standard library) and have it adopted in the C++ standard and supported by all the compilers etc, what would it be and why?

  25. C++ without the C by kthreadd · · Score: 4, Interesting

    Apple recently introduced a language they call Swift or Objective-C without the C. It is technically a completely different language from Objective-C though. When C++ started out it had the major benefit that it was (mostly) compatible with C which at the time was immensely popular, making it trivial to mix new C++ code with existing C code. Today C is still a popular language but not as widely used as it once was. Assuming that C++ could drop C compatibility, how would you take that opportunity to improve C++?

  26. EST? or EDT?!? by GNious · · Score: 2

    The linked G+ post says "August 20th, 2014 at 12:30pm EST to 2:30pm EST", but August 20th, 2014 is during Summer Time/Daylight Saving Time ...

    So, is is 12:30pm EST, or 12:30pm EDT ??

  27. Re:Why is C++ such an utter pile of shit? by DickBreath · · Score: 3, Funny

    There are optimizations you can use to improve your experience with C and C++.

    Just insert these into your header files for both time and space improvements in your compiled code.

    #define struct union; // uses less memory
    #define while if; // makes code run faster

    Now how can you say bad things about a language that is so easily improved?

    --

    I'll see your senator, and I'll raise you two judges.
  28. Personal programming projects by kthreadd · · Score: 3, Interesting

    Apart from work, do you have any personal programming projects going on? Which type of programming do you like most and is there a particular project that you would like to implement?

  29. Fizz Buzz by kthreadd · · Score: 2

    In C++ how would you write the most elegant solution that prints numbers from 1 to 100, replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz"?

  30. Re:Multiple Return Types? by dentin · · Score: 2

    The last thing C++ needs right now is another complex feature which adds more syntax and fundamentally new operation.

    --
    Alter Aeon Multiclass MUD - http://www.alteraeon.com
  31. Re:Multiple Return Types? by dentin · · Score: 2

    Hopefully, not for a long time. C++ doesn't need more complexity at the moment. It needs less.

    --
    Alter Aeon Multiclass MUD - http://www.alteraeon.com
  32. Code rejuvenation by SansEverything · · Score: 4, Interesting

    You speak alot about code rejuvenation and bringing old code to new standards. As you are working on C++14, many compilers do not fully support C++11 yet. In the past, it was even worse. Don't you think that this lack of feature support from compilers is a major problem and the biggest obstacle to code rejuvenation?

  33. Feature Cut by BlackHawk-666 · · Score: 2

    Are there any features of the language that you wish hadn't been added or could now be removed?

    --
    All those moments will be lost in time, like tears in rain.