Live data from Hacker News

A list of modern C++ features

github.com

31–40 of 68 posts

Re: A list of modern C++ features

#32
post #16

Yeah more features is exactly what C++ needed... Am I the only one who uses C++ as C with classes? Sometimes I use vectors or strings and I like default values in functions and other minor improvements to C. I don't want to reimplement the n'th version of string concatenation when I can just use the "+" operator, sure... and there starts the rabbit hole. Before you know it you have a "protected abstract virtual base…

No, you aren't. I've also seen (and done) C++ used as C with classes in embedded systems development, where you really need to be sure that the compiler isn't doing something you don't expect.

Re: A list of modern C++ features

#33

Most features are very good. My favorite ones are range-based loops, lambdas, and strongly-typed enums. The things I dislike most are pairs and tuples. They make the code enormously harder to read, understand and debug, compared to non-standard classes or structures with meaningful member names. Even this guide promotes them in “using Coordinate = std::pair ;” Please, never do that, create your own class with x/y or…

Sometimes all the meaning is in the name of a thing (or in the name of a function returning such a thing) and member names dont help but hurt. x/y is a good example, why not a/b? I prefer not having to make these decisions. Also tuple assignment syntax is very nice from a usability standpoint (I don't think C++ has it, but e.g. Python has).

Re: A list of modern C++ features

#34
post #25
post #8

Earlier quoted context omitted.

Or even better, at some point they should introduce "safe mode" or "strict mode", where you turn on a compiler flag.

aka -Weverything ;)

Which is hella annoying. -Wall -Wextra is very needed, -Wconversion is nice but already borderline annoying, but enabling everything would just be a mess.

Re: A list of modern C++ features

#35
post #22

The one feature that really annoys me is the std::optional. This is awesome and very needed feature however it is too clunky for something that should be used very frequently. Swift does such a nice job with its '?' operator, I wish C++ had something similar.

C++ tries to put features in the standard library instead of the core language whenever possible. The downside is they can't add new syntax.

Re: A list of modern C++ features

#36
post #25

Earlier quoted context omitted.

aka -Weverything ;)

Which is hella annoying. -Wall -Wextra is very needed, -Wconversion is nice but already borderline annoying, but enabling everything would just be a mess.

-Wc++98-compat is especially annoying.

Re: A list of modern C++ features

#37

Most features are very good. My favorite ones are range-based loops, lambdas, and strongly-typed enums. The things I dislike most are pairs and tuples. They make the code enormously harder to read, understand and debug, compared to non-standard classes or structures with meaningful member names. Even this guide promotes them in “using Coordinate = std::pair ;” Please, never do that, create your own class with x/y or…

Sometimes all the meaning is in the name of a thing (or in the name of a function returning such a thing) and member names dont help but hurt. x/y is a good example, why not a/b? I prefer not having to make these decisions. Also tuple assignment syntax is very nice from a usability standpoint (I don't think C++ has it, but e.g. Python has).

C++17 adds tuple unpacking under the name "structured bindings"

    auto [a, b] = function_returning_pair();
Of course, tuple unpacking was already possible before if the variables were already declared:

    int a, b;
    std::tie(a, b) = function_returning_pair();

Re: A list of modern C++ features

#38
post #14
post #7

This made me think of the passage below from Edsger Dijkstra's ACM Turing Lecture from 1972. Back then there was no C++. "I remember from a symposium on higher level programming language a lecture given in defense of PL/1 by a man who described himself as one of its devoted users. But within a one-hour lecture in praise of PL/1. he managed to ask for the addition of about fifty new “features”, little supposing that t…

And every time there was a language designed against PL/I like languages, with the goal of fighting complexity, its adoption by the industry lead to feature growth and becoming just as complex, usually with solutions hindering by backwards compatibility. Yes C++ is complex, but so are Python, Ruby, Ada, Fortran, C#, F#, Haskell, OCaml, Java... Even Go will get caught in the complexity game if it gets enterprise adopt…

I won't necessary call out Java as a complex language. However in not being so complex a language it sacrifices a lot of expressiveness found in other languages.

Re: A list of modern C++ features

#39

Most features are very good. My favorite ones are range-based loops, lambdas, and strongly-typed enums. The things I dislike most are pairs and tuples. They make the code enormously harder to read, understand and debug, compared to non-standard classes or structures with meaningful member names. Even this guide promotes them in “using Coordinate = std::pair ;” Please, never do that, create your own class with x/y or…

Sometimes "using Coordinate = std::pair;" does have upsides, though. One example would be when using a serialisation library that knows how to handle pairs. In that case you don't have to add (de-)serialisation code to every new class. It's also nice to be able to use std::tie for unpacking: "std::tie(x, y) = get_coords(blah);"

If you use the members a lot, a struct with named members really is much easier to read, though.

Re: A list of modern C++ features

#40
post #23
post #19

Earlier quoted context omitted.

The big difference here is how additions in C++ tend to work - e.g. keeping all of the deprecated ill-defined legacy and growning features on it like tumors until there are no more symbols left. Unlike Ada and Python which aren't afraid of throwing away poor design and were overall more thought out in the first place (especially Ada). Its not a "complexity game" in so much as poor design being over-compensated for. C…

How specially Ada?! The only thing Ada has thrown away was GC support that no compiler vendor has ever bothered to implement. What other features were thrown away across Ada83, Ada95, Ada2005 and Ada2012? If I present you Ada random code snippet X, are you sure you will be able to say which language version it requires? Also Python is the poster child of what happens when you throw compatibility away.

>Also Python is the poster child of what happens when you throw compatibility away.

And what, exactly, happened?

For years I avoided Python3. Updating my code base was a hassle I did not want to deal with.

Finally, a few months ago, I had some spare time and took the dive.

And nothing bad happened. I did not even spend hours on it. At this point, all the libraries I need exist for Python3, and the automated tools update my code for Python3 without manual intervention almost every time.

Post reply on HN