Slashdot Mirror


New C++ Features Voted In By C++17 Standards Committee (reddit.com)

New submitter lefticus writes: The upcoming C++17 standard has reached Committee Draft stage, having been voted on in the standards committee meeting in Oulu, Finland this Saturday. This makes C++17 now feature complete, with many new interesting features such as if initializers and structured bindings having been voted in at this meeting.

An [audio] interview with the C++ committee chair, Herb Sutter, about the status of C++17 has also been posted.

33 of 286 comments (clear)

  1. Sweet by Kohath · · Score: 5, Insightful

    C++ needed more features. Some C++ books aren't even 1000 pages long.

    1. Re:Sweet by Longjmp · · Score: 5, Funny

      C++ needed more features. Some C++ books aren't even 1000 pages long.

      I agree! And more use of the "const" keyword.
      I want to write something like
      const int const foo(const*(const) int const a) const: const {}
      and
      for (const i = 0;const i(const)++; i and finally:
      const return const 1 (const const const)

      --
      There are fewer illiterates than people who can't read.
    2. Re:Sweet by NotInHere · · Score: 2

      Sane languages have their stuff const by default, and you write mut if you want something changeable.

    3. Re:Sweet by 110010001000 · · Score: 2, Informative

      You mean Rust. Rust is a terrible hipster language that won't last 5 years. C++ is going on 40.

    4. Re:Sweet by pedz · · Score: 4, Funny

      C++ needed more features. Some C++ books aren't even 1000 pages long.

      I agree! And more use of the "const" keyword. I want to write something like const int const foo(const*(const) int const a) const: const {} and for (const i = 0;const i(const)++; i and finally: const return const 1 (const const const)

      Replace const with spam and you would have yourself a Monty Python skit.

    5. Re:Sweet by ffkom · · Score: 4, Informative

      Just because you are unable to cope with C++'s richness of features does not mean it is a bad thing.

      After all, C++ is the one language that

      • supports a large selection of programming paradigms, and does not declare just a single one to be "the only one you need".
      • does not depend on one company or organization, but is truly a federated effort, with many compilers to choose from.
      • allows you both low-level / hardware-level programming as well as very-high-level programming just using some ready made class library / run time environment (like Qt).
      • has a responsibly acting committee doing a good job overlooking the long-term language evolution. So much unlike many other programming languages, were inexperienced people have introduced the same mistakes over and over again, because nobody was there to question them.
    6. Re:Sweet by ffkom · · Score: 5, Funny

      No Perl is for those who insist that every possible sequence of bytes shall be a valid program, because otherwise there is unnecessary redundancy in the code.

    7. Re:Sweet by Dutch+Gun · · Score: 5, Interesting

      You need to divide C++ into two sections: Stuff that's useful for applications, and stuff that's mostly relevant to library writers. A lot of the really hairy stuff is mostly for the library writers. Moreover, a lot of the complexity of C++ (and corresponding slowness of its compilers) comes from compatibility with C and with older versions of itself. If you strip away all that, the core language that most people deal with isn't quite as daunting.

      That being said, nobody is claiming that C++ isn't a difficult language to master. Scott Myers has made a career of pointing people away from it's darkest corners, after all.

      But really, C++ programming took a quantum leap forward with C++11, and C++14 just filed away some of the rough edges. It's hard to explain to non-C++ programmers what a transformation it was. I'm not expecting nearly as much with C++ 17, but I look forward to seeing if any of the proposed features will be useful in my day-to-day work.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    8. Re:Sweet by DougReed · · Score: 2, Insightful

      This made me laugh. Having written programs in most of the languages living people have heard of, Perl is the one language I can write something in and 15 minutes later can't figure out what it does! I always called Perl the perfect write only language.

      Having said that... I could write a Perl program in 5 lines that I would spend HOURS trying to figure out how to do in just about anything else. ... but if it's obscure I better add a comment to say what it is supposed to do. Because given problem 'x' I would be like 'I can do it like this' but a year later with no context it's ... 'What the hell is this supposed to do??? It's worse if it involved Perl's RegEx extensions and you don't remember what the incoming string contains. Just looking at the line makes you want to jump off of a bridge instead of trying to parse it in your head.

    9. Re:Sweet by Dutch+Gun · · Score: 3, Interesting

      The C++ committee (rightly so, I think) tends to prefer library-based solutions whenever possible, because there's less chance of disruptive changes when you add new libraries. Only when a library solution won't work do they turn to new language features. You'll also notice they really don't like adding new keywords at this point.

      A lot of people seemingly don't understand how important this backwards compatibility is (presumably because they're always rewriting stuff using the latest new-and-shiny tech), but there are many places that have code that's decades old. It's a terrible idea to go and tinker with robust, well-tested code just because it's not the latest new-and-shiny. The careful attention to backwards-compatibility causes a lot of issues (like slow compile time / language complexity, etc), but it's also one of C++'s greatest strengths. People know that an investment in C++ code will be working just fine for decades to come. I mean, they're just now depreciating trigraphs, for pete's sake. Apparently IBM still has code that uses those and opposed their removal in the last standards round, but they're a tiny minority and couldn't sway the committee this time. No one else even knows what the hell they are.

      Look how much of a rift the Python 2 to 3 change caused. Even if it's good for the language, incompatible changes that occur too quickly can cause real problems for a programming community. Even after 8 years, a significant percentage of Python programmers are still using 2.x instead of 3, mostly because of dependencies holding them back.

      Nothing would kill new C++ features faster than incompatibility with legacy code. And in fact, one of the nice things about C++ is that it typically allows programmers to start adding those new features piecemeal as they get more familiar with them and as they get compiler support.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    10. Re:Sweet by Pseudonym · · Score: 3, Insightful

      Haskell's unofficial motto is "avoid success at all costs", which is how it has remained pure and hipster. Haskell will always be the language of the future, in the sense that unless you work for a European bank you won't be using it yourself, but the new features in your favourite language will probably come from Haskell.

      Avoiding success is a lesson that Rust has not learned.This is why Rust will become obsolete and Haskell will not.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    11. Re: Sweet by Samantha+Wright · · Score: 2

      You mean "(You". ... The hyphen has, tragically, been vanishing from American English stylebooks for decades, driven by a desire for minimalism. This usually results in something harder to read, but as long as the compound can lose the hyphen without creating genuine ambiguity ("Nice-ass car!") then it's considered fair game. Obvious exceptions include but are not limited to ranges and constitutive compounds like the Banach–Tarsky paradox, both of which are correctly written with en dashes anyway. Unrelatedly, excessive hyphenation is a great way to spot a German.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    12. Re: Sweet by The+Evil+Atheist · · Score: 2

      If you use any part of the standard C++ library, you're using templates. And if you're not using iterators, I'd expect you're writing too many error-prone loops that are already implemented by the STL algorithms. If you're using any form of smart pointer, you're using template. If you're not using a smart pointer or an STL container, you most probably have leaks. And you're definitely not using lambda functions which are useful in any language.

      The idea that Java and C programmers should be able to read the code is ridiculous, not least of which Java recently just got its own version of lambda functions and streams API. Programs should not be written in a dumbed down subset of ANY language for the lowest denominator. There comes a point where you simply must learn the advanced or new parts of a language, be it C++ or Java or Javascript, nowadays. In the case of those three languages, the new parts added in recent years simplify what was previously complicated code. By sticking to an old subset, you are actually keeping your code more complicated than it needs to be.

      Rejecting a new keyword makes sense. It doesn't reveal any bad design. Adding new keywords increases the risk of breaking existing code that uses common English words. Not many people want to appreciate this, it seems. You can't in one breath criticize C++ for being complicated at the same time as criticizing it for not complicating things with new keywords.

      --
      Those who do not learn from commit history are doomed to regress it.
    13. Re:Sweet by colinrichardday · · Score: 2

      has a responsibly acting committee doing a good job overlooking the long-term language evolution. So much unlike many other programming languages, were inexperienced people have introduced the same mistakes over and over again, because nobody was there to question them.

      To be pedantic here, I'd prefer if they were overseeing it.

  2. c++ is now the world's most complex language by Anonymous Coward · · Score: 4, Insightful

    I look back fondly at "c with objects". At least I could decipher the error messages.

    1. Re: c++ is now the world's most complex language by 110010001000 · · Score: 5, Insightful

      C++ is actually used in real programs for a large amount of software you use every day. Go, Swift and Rust aren't even used in the flagship products written by the organizations that created the languages. That should tell you what the difference is.

    2. Re: c++ is now the world's most complex language by Cyberax · · Score: 3, Informative

      Go is used widely in Google, including for its cluster management system (Kubernetes). Rust is being used to write the next version of Mozilla's rendering engine.

    3. Re: c++ is now the world's most complex language by NotInHere · · Score: 2

      Swift is used as app programming language for apple's flagship products.

  3. Sigh by Man+On+Pink+Corner · · Score: 5, Funny

    Still no functional gonkulators. Still no encabulation templates. Still no dichroic monads or parameterized gussets. When will the C++ committee ever get around to adding modern language features that users actually want?

  4. If initializer by Carewolf · · Score: 4, Insightful

    I appreciate the idea behind if initializer. This is actually a somewhat common pattern.

    if (MyClass *p = getMyClassOrNull() {
        p->doYourThing();
    }

    But I fear using initializer statements easily gets too long for a line, and couldn't it already be done with the comma operator?

    1. Re:If initializer by Carewolf · · Score: 2

      I really hate it because it now makes ( ) a scope boundary. Previously, you could just assume looking for { } as a scope boundary. This is important because it makes it harder to debug while half asleep.

      It is not the parenthesis that is the scope boundary, it is the keyword. This is no different from 'for' statements where 'int i' is often declared. And note my example above already works right now, though it something that is either encouraged, or heavily frowned upon in coding styles. It looks weird and unnatural unless you are used to it.

    2. Re:If initializer by Carewolf · · Score: 3, Interesting

      No because you can't put a declaration inside the if statement right now. You could use the comma operator to give an already declared variable a value before the boolean expression, but the variable would have scope outside of the if statement.

      Yes, you can. The example I showed above works right now, and always have. The problem is that it declarations evaluate to their values, so you can only do it if the value is something that has a useful boolean conversion (like not-null of pointers). The standard would expand the same to more types of expressions. But I can't see why this wouldn't already work:

      if (MyClass *p = getMyClass, p && p->ofTheRightType())

              p->doTheRightThing()

      Wait, I think I figured it out. The comma operator doesn't work after declarations. In a declaration a comma signifies a declaration of another variable of the same type.

  5. Missing features by rroman · · Score: 3, Interesting

    Unfortunately the most important features weren't added. Concepts, modules, reflection and concurrency ... those would actually fixed almost all the things, where c++ is lacking now. Hope those will get into the next standard at least.

    1. Re:Missing features by istartedi · · Score: 3, Informative

      I'm still waiting for it to have a poorly specified implementation of *all* of common Lisp.

      --
      For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
    2. Re:Missing features by Pseudonym · · Score: 2

      A poorly specified one? That is literally JavaScript.

      No, it isn't! JavaScript is a very well-specified implementation of all of Scheme, conveniently wrapped in a syntax which makes it as difficult as possible to actually use that Scheme implementation.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  6. Yet... by fozzy1015 · · Score: 2

    There's still no std::string split() method.

  7. They also forgot by presidenteloco · · Score: 5, Funny

    Open closures, interior decorators, and conditional consts. In protest I'm gong back to c++--

    --

    Where are we going and why are we in a handbasket?
  8. Is 4 errors per line typical for Rust programmer by raymorris · · Score: 2

    use rust = Use Rust.

    Its simpler safer and its better = It's simpler, safer, and better.

    You wrote two lines. With 8 errors. Is four errors per line about average for Rust programmers?

  9. You want them to rush in incomplete features?! by Anonymous Coward · · Score: 4, Insightful

    What are you trying to say? That they should rush in features that haven't been thought through? That they should put half-arsed or broken features in place just to say that they have? That they should then support these broken features for decades, since that's how long C++ projects tend to live?

    Look, if you want a language with buzzword features thrown in left and right, with changes to these features happening just about every release, then maybe a programming language like Rust is what you're looking for. C++, on the other hand, is a language meant for professionals to use when developing complex systems that won't just be used next week, but will be used 15 or 20 years from now, assuming they aren't still being used long after that. Those standardizing C++ have a huge responsibility on their shoulders. They can't goof around with C++. If a change is made to the language, it has to be thought out thoroughly and it has to be the right thing to do.

  10. Not impressed. by fahrbot-bot · · Score: 2

    I'm not that impressed with the "if statement with initializer" addition and especially not impressed with one of their examples that use it to make things more compact. I don't like declaring the same variable twice and think more traditional coding would actually be cleaner.

    status_code foo() {
    int n = get_value();
    if (status_code c = bar(n); c != status_code::SUCCESS) { return c; }
    if (status_code c = do_more_stuff(); c != status_code::SUCCESS) { return c; }
    return status_code::SUCCESS;
    }

    Seems like a pretty pointless addition.

    --
    It must have been something you assimilated. . . .
  11. Re:c++ needs to know its place by ffkom · · Score: 3, Informative

    Is that what they told you in MBA school? Funny enough, it's managed code such as PHP, JavaScript and managed code runtimes such as Flash (for ActionScript) which have brought on the vast majority of security flaws on the InterNet.

  12. Obligatory video by apilosov · · Score: 3

    All you need to know about C++17 is here: https://www.youtube.com/watch?...

  13. No. by rjh · · Score: 3, Funny

    I started programming in C++ in '89. Templates were still new, but most of the language was stable. C++ code I wrote in '89 is still readable and compilable today. I know people who started with C++ in 1981, when it was still Bjarne's skunkworks project. The first public release was '83, making C++ 33 years old -- closer to 40 years old than 25.