Live data from Hacker News

Ask HN: How to refresh on modern features of C++?

news.ycombinator.com

41–50 of 63 posts

Re: Ask HN: How to refresh on modern features of C++?

#42
post #6

Earlier quoted context omitted.

cppreference.com is a good resource too. It's updated frequently. http://en.cppreference.com/w/

I can't stand that site. I try to use the old SGI stl reference whenever I can.

whoa really? To me cppreference is the single best example of code documentation I've ever used. Clean, easy to search, thorough but skimmable listing of interfaces, great example code, modifiable example code, provides necessary information not part of function declarations (iterator invalidation rules). I'm surprised you prefer the far more bare bones SGI version.

Re: Ask HN: How to refresh on modern features of C++?

#44

A (maybe unrelated) question about companies like Google and Faceook, which are C++ powerhouses: how many (if any) of the C++11 or C++14 features have they approved for use in production code?

For Google open source projects, all C++11 features are approved except the following ones[0]:

    Functions (other than lambda functions) with trailing return types, e.g. writing auto foo() -> int; instead of int foo();, because of a desire to preserve stylistic consistency with the many existing function declarations.

    Compile-time rational numbers (), because of concerns that it's tied to a more template-heavy interface style.

    The  and  headers, because many compilers do not support those features reliably.

    Default lambda captures.
For Chromium, it's a completely different set of rules[1].

[0] http://google-styleguide.googlecode.com/svn/trunk/cppguide.h...

[1] https://chromium-cpp.appspot.com/

Re: Ask HN: How to refresh on modern features of C++?

#45

same with me, I am a very old c++ coder, learned during 2001-2002. Now I am doing TA at a graduate school, instructing a course on c++. It helped me to learn a lot of new stuffs on c++11. "C++ Primer", by Lippman is the book that we try to follow.

If 2001-2002 is old, then what is 'used for 7 years starting 1994'?! :)

I will be curious to read the replies here, as a year ago I was considering different languages and environments for a cross-platform project, and ultimately C# (yes, C#) won out over C++. To be fair the requirements for the project meant that runtime performance wasn't so critical, but preventing the developer - myself! - from making mistakes was.

Maybe it is because of my age, but despite having lots of experience with C++ and a mostly pleasurable love-sometimes hate attitude towards it, I couldn't imagine it making first choice for me these days for new projects.

Re: Ask HN: How to refresh on modern features of C++?

#46
post #27

Earlier quoted context omitted.

People who learn C++ this way tend to miss stuff out, I think - there are a lot of thing that you can just muddle your way though without really understanding. I'm sure there are some people that think this will be OK; after all, lots of people say you don't really have to understand templates unless you're writing a library (and so on). But I don't think it will be OK. There was very little in C++98 (that I knew wel…

obviously we disagree! i think it's ok to miss out on language features. templates, as you say yourself you're ok not to know. you're also not ok not to know exceptions. there's other stuff too, you can get away without the C preprocessor. C++ is too big to know all of and it's a waste of time to invest time trying to, unless you are on a standards committee or are writing a compiler...(and even then you can get away…

> obviously we disagree! i think it's ok to miss out on language features.

Sure, but there are a ridiculous number of edge cases which result in undefined behavior -- this is something that cannot be avoided when learning C++. You really need to understand what undefined behavior means and what precautions you need to take to avoid it. (Don't get me wrong, recent standards let you write code that's a lot less likely to run into UB, but you need to learn that from somewhere. You should definitely not be approaching modern C++ as an improved C!)

Re: Ask HN: How to refresh on modern features of C++?

#47

Earlier quoted context omitted.

obviously we disagree! i think it's ok to miss out on language features. templates, as you say yourself you're ok not to know. you're also not ok not to know exceptions. there's other stuff too, you can get away without the C preprocessor. C++ is too big to know all of and it's a waste of time to invest time trying to, unless you are on a standards committee or are writing a compiler...(and even then you can get away…

unless you are on a standards committee or are writing a compiler... Or you work on an existing codebase. Most C++ code that I worked on had templates, exceptions, and used the C preprocessor. I used to have your attitude. This works for many languages, e.g. if you know some of the syntax of Python or Go and the usual stuff from the standard library, you can get pretty far. If you want to write modern C++, this is no…

Modern C++ is a moving target. By the time you get around to doing a project with one set of features they've been made redundant. Exceptions are a good example of this with noexcept etc coming in and replacing what went before.

I know nothing of haskell. My point is that you should learn the features of the codebase you work on, and it's a waste of time to learn all features, ultimately for a codebase you are not working on or may never work on.

incidentally, ditto, i used to have your attitude.

Re: Ask HN: How to refresh on modern features of C++?

#48
post #36

Earlier quoted context omitted.

I agree; sometimes you have to start somewhere. Then come back and improve knowledge. Trying to be a theoretical expert early on will bite you

The thing is that most of the things that your parent mentions are not just some theory. Exceptions, templates, and the C preprocessor are used in most real-life C++ code. I think starting from somewhere with modern C++ means not starting at C strings, arrays, and bare pointers but starting with STL containers, STL algorithms, and smart pointers etc. to build good habits. But eventually any good introduction has to c…

I agree that picking a subset is the way to go. Google avoid two out of the three i mentioned that you take issue with avoiding.

Places I have worked the code is divided into libraries and coding standards per library are different to the whole. The point is to lazily learn the part that the codebase you are working on uses and get cracking rather than waste time getting book smart on parts you may never use.

Re: Ask HN: How to refresh on modern features of C++?

#49
post #44

A (maybe unrelated) question about companies like Google and Faceook, which are C++ powerhouses: how many (if any) of the C++11 or C++14 features have they approved for use in production code?

For Google open source projects, all C++11 features are approved except the following ones[0]: Functions (other than lambda functions) with trailing return types, e.g. writing auto foo() -> int; instead of int foo();, because of a desire to preserve stylistic consistency with the many existing function declarations. Compile-time rational numbers ( ), because of concerns that it's tied to a more template-heavy interfa…

OSS projects would, presumably, have far fewer restrictions than internal revenue-bearing production use?

Re: Ask HN: How to refresh on modern features of C++?

#50

Earlier quoted context omitted.

obviously we disagree! i think it's ok to miss out on language features. templates, as you say yourself you're ok not to know. you're also not ok not to know exceptions. there's other stuff too, you can get away without the C preprocessor. C++ is too big to know all of and it's a waste of time to invest time trying to, unless you are on a standards committee or are writing a compiler...(and even then you can get away…

> obviously we disagree! i think it's ok to miss out on language features. Sure, but there are a ridiculous number of edge cases which result in undefined behavior -- this is something that cannot be avoided when learning C++. You really need to understand what undefined behavior means and what precautions you need to take to avoid it. (Don't get me wrong, recent standards let you write code that's a lot less likely…

the edge cases are multiplicative, the more features you use, the more they interact. therefore by reducing language features that you use you reduce the number of edge cases you run in to. most shops agree on a subset of C++ before embarking on a project.

i didn't say to approach C++ as an improved C. you are more likely to learn undefined behaviour from compiler warnings than reading a merry array of 500 page books before sitting down to not finish a program.

Post reply on HN