Hacker News new | past | comments | ask | show | jobs | submit login

What would be the best learning path to take for young people wanting to learn C++ today, especially with a focus on free software? Thanks for your attention!



First of all, and most important one, learn C++ idioms, not C.

This means making use of library types for memory allocation, vectors and strings.

There is a place for old C style low level features, but those should come later, after the safer concepts are already ingrained.

Kate Gregory's “Stop Teaching C" talk at CppCon 2015 explains better than me.

https://www.youtube.com/watch?v=YnWhqhNdYyk

Get a nice IDE, QtCreator, Clion, VC++ Community, KDevelop, XCode.

Besides the "Tour of C++", check Stephan T. Lavavej talks at Channel 9.

"Core C++ Lectures"

https://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavav...

"Advanced STL", these ones only when you already have a good understanding of STL as user

https://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavav...

Also check video presentations from NDC, ACCU, CppCon, CppNow and C9 Going Native.


> Get a nice IDE, QtCreator, Clion, VC++ Community, KDevelop, XCode.

No, not Xcode. Apple is not enthusiastic about c++ support and using Xcode is nice for debugging only, but write your code in something else. A lot of Mac devs will use Clion or for me, emacs, and then deploy or debug with Xcode when necessary.

Xcode doesn't format a lot of C++11 features properly and it's just a bad editor in general, even if you are using an "Apple-approved" language, which is why a lot of Swift/ObjC devs still use another JetBrains product, AppCode, for actual editing.


It is been awhile, I know Apple is mainly Objective-C/Swift shop but given the C++ use on IO Kit and Metal shaders I thought XCode had improved meanwhile.


I agree with you for everything except this one statement:

> First of all, and most important one, learn C++ idioms, not C.

I think it would be better to learn both. C programming really has its place, and it gives you a model to understand how the sausage is really made. I know lots of C++ programmers who couldn't even begin to understand how half the things in their language work, this leads to completely needless performance loss (like using vectors for statically-sized arrays of data, which I recently replaced with a C array in a piece of game modelling software for a 20-30% improvement in runtime).

The fact that you consider this the most important one is outlandish. I think it's easily more important to teach the tradeoffs and models involved in things like unique_ptr, rather than creating a cargo cult for abstractions that turn out to be useless half the time.

C++ programmers really need to learn C, at least after their first year of blissful ignorance. Don't stop teaching C.


>using vectors for statically-sized arrays of data, which I recently replaced with a C array

See the idea is you can use std::array, so you can use modern idioms (and at() for bounds checked access).


Sorry, but on this one given my comments history, I am with Kate Gregory.

C style code has only one place, unsafe C++ coding for optimization purposes, only after validated through the use of a profiler.

In 99% of the applications it is usually irrelevant for what the users are expecting, and there are even some nice talks at Nokia Wrocław conferences, where the presenter was able to generate better compacter code with modern C++ instead of classical C code.

It was the C mentality brought into C++, back when learning C before C++ was the only path as C compilers were adding C++ support, that brought the daily CVEs we nowadays endure in such codebases.


The previous poster wrote in his 3rd paragraph

"There is a place for old C style low level features, but those should come later, after the safer concepts are already ingrained."

And I agree that teaching idiomatic C++ is important and C stuff is an extension.

If replacing vector with a C array gives you 20-30% my general assumption is that vector was used wrongly and there were too many copies happening and passing a pointer around avoided them.

And yes, when teaching pure C++ students will also easily create too many copies, but that's better than all the buffer overflows, null pointer dereferences etc. happening to students of C. Such bugs cause frustration, but students need results which give satisfaction.


I think a better way to phrase it would be "stop teaching C to people who think they're learning C++". I completely agree that doing even just a couple of weeks of plain C is an incredibly useful endeavour, but I saw the "C with classes" idiom a few too many times back when I was still doing C++.


Is the Chrome source good source code to read? I always find they very organized in the high level, but don't know if its actually good C++ code.


Yes, it is. Maybe not for the begginer, but Google open source C++ stuff tend to have a great code quality.

Also, the modern open source C++ stuff from Microsoft is also great.

Go for Chrome, V8, Dart, ChakraCore, the C++ part of DotNet VM.

But the only "problem" with them, is that they use their own sort of smart pointers, but if you know that they map 1-1 to smart pointers from std:: when you need to use the std ones, its not a big deal.

Chrome for instance have scoped_ptr = unique_ptr, scoped_refptr = shared_ptr, etc..


Any examples of code bases using these modern features like co-routines? I'd love to see an example of it being used in real code.


Only Microsoft is using co-routines in production code via UWP.

CppCon 2016: Kenny Kerr & James McNellis “Putting Coroutines to Work with the Windows Runtime"

https://www.youtube.com/watch?v=v0SjumbIips


While it doesn't use coroutines that I know of, the Dolphin emulator[1] generally makes good use of modern C++ features.

[1]: https://github.com/dolphin-emu/dolphin


First decide if it's really something worth your time. Then, spend several years playing with the std lib and maybe dabble with Boost. Read stackoverflow threads tagged with [c++] sorting by vote count descending. Read the tests in popular github c++ projects. Read A Tour of C++. Most importantly, write and rewrite lots of code, test it, debug it, and try out cool ideas you think of. If you get stuck, context shift to another task where you're not spinning your wheels.


Excellent question, and one for which I've not found a satisfactory answer. Perhaps some of the HN wisends can chime in. I believe with some linters (clang, etc) you can encourage your tools to slap your wrists if you code in a bad style using outdated techniques.


Read lots of Scott Meyers and force yourself to read STL code. Bjarnes books are good but a bit pricey so I'd avoid paying for them.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: