r/cpp • • Apr 23 '16

Just started coding with C++

I just started coding with C++ not too long ago, but I've had alot of experience with other coding languages (Java, Javascript, HTML, Python.) But if I'm aiming to make games with C++ one day (After years and years of practice of course) what do I need to learn? What books do you recommend? What exercises should I practice? As far as I know there's no website to 'teach' the subject (Like CodeAcademy and what not), so what would you recommend to get me started?

1 Upvotes

32 comments sorted by

View all comments

8

u/_lerp Apr 23 '16

Effective Modern C++ by Scott Meyers

and IMO the thing that sets C++ apart is the metaprogramming, i.e. templates.

17

u/lex99 Apr 23 '16

I strongly disagree with advising newcomers to learn metaprogramming. It's the most advanced aspect of C++, hard to follow, write, and debug. You can go far in c++ without it.

I would instead advise the newcomer that c++ gives you total control of your system (modulo the compiler) and with it you can really understand how every action the computer takes is due to some value at a specific location in memory being operated on, or some system call being executed, and there's NO magic anywhere. For folks that came up in Python, ruby, JS, etc, there's a large abstraction between the code and the machine.

-1

u/flyingcaribou Apr 23 '16

I would instead advise the newcomer that c++ gives you total control of your system (modulo the compiler) and with it you can really understand how every action the computer takes is due to some value at a specific location in memory being operated on, or some system call being executed, and there's NO magic anywhere. For folks that came up in Python, ruby, JS, etc, there's a large abstraction between the code and the machine.

Why not just do C, then?

5

u/DarkLordAzrael Apr 23 '16

Generic code ( templates without metaprogramming ), function overlaoding, RAII, a standard library that is actually useful, operator overloading, a type system that isn't mostly just throwing out type info at every opportunity, need I go on?

-1

u/LowB0b Apr 24 '16

???

That has nothing to do with the first answer, he was advocating C++ because he says there "is nothing going on behind the scenes" (no magic) while in fact there is. The examples you cited are "magic" and I would even dare to say that the concepts you are talking about are for people who have been programming for a while.

C is so simple, the hardest thing about it is pointers. C++ is way more complex. I think the former is better for someone who wants to learn how code is treated by the machine.

3

u/lex99 Apr 24 '16

Actually, the Magic I was referring to was runtime magic, whereas a lot of C++'s features are compile-time. I would agree though that there's a lot of overlap or maybe perceived overlap. A new person might regard constructors and destructors as magic, yes.

The kind of magic I was referring to, out of langs like JS or Python, are things like function closures (and associated variable capture) and the fact that without pointers and memory references, we just have "objects" that somehow float in memory. Due to the pains of mem mgmt in C/C++, you'll never avoid the concrete reality of what an allocated object really is (otherwise, you just segfaulted or leaked memory).

1

u/lex99 Apr 24 '16

I'm saying metaprogrammer is too out there, hard to do, and unnecessary, for a new C++ to aim to learn. I don't think it's THE reason one would use c++.

But even without metaprogramming, C++ has lots of critical improvements over C.

I wasn't saying though "pick the absolute least-magical lang."