Advertisement Jump to content
Sign in to follow this  
BogdanV

Getting a solid grip on C++ : Where to go next?

This topic is 1880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 I studied C++ during my college/high school (ugh, these language variations between US and British English can get pretty annoying sometimes) days: syntax, some algorithms for sorting, graphs, recursive functions etc. mostly basic stuff. Now, being in my second year at University, I realised I've spent a ridiculous amount of time almost exclusively in C# (and Unity to be more precise), much to the detriment of my general programming skills.

 

 Managed languages are awesome. Heck, I'd say they're the best thing since sliced bread but they kind of keep you ignorant towards low-level stuff and its this ignorance that I want to address.

 I had a chance to talk to someone from Microsoft at a recent conference and he simply told me that the best way to go forward is to "learn C++". That was a pretty humbling experience as mundane as that statement might seem, realising that there's a whole universe out there that I probably don't know. He also suggested looking into DirectX's HLSL or for that mater, anything that "talks" to the graphics card.

 

 What I already started to do was to dig into OpenGL and I'm currently using OpenGL: A Primer by Edward Angel as my main learning material, however, I still need to address the more general issue with C++... and I'm not sure where to start because there seems to be a lot of things that I probably don't know.

 

 I know for instance memory allocation is a big part of C++ which I haven't learned (and managed languages like C# aren't very helpful here xD). Optimising code using binary operations (or heck, even assembly although this cuts portability) is another one that I think would be good to know.

 

 I've also seen Exceptional C++ mentioned here and there so this might be a good starting point (if the library didn't run out of it).

 

 What are your thoughts on this? What C++ concepts / aspects should I try to study next?

 

[Later Edit: Should've changed the title to "Getting Better at..." because I already know something]

Edited by BogdanV

Share this post


Link to post
Share on other sites
Advertisement

Studying stuff for the sake of studying doesn't go anywhere in my opinion. You just have to know that a feature of a language exists and what it does, but if you want to actually learn something, you should establish yourself a project to work on. Clearly set up a goal for you: I want to do an application that does that and that. Design it and then start working on it. Pretty early in the development process you will hit some problems, and then you will have to find solutions for them. This is the best way to learn a programming language. Languages are tools that help you achieve your goals, they have no purpose by themselves. So studying a language out of a clear context (like making an application) is pointless.

Share this post


Link to post
Share on other sites

You should first of all learn what you are comfortable with and what you will need, or what you think you'll need. If you can easily afford the extra time, by all means go for C++, but otherwise it may be wiser to perfect your skill in C# (since you've been doing this for two years).

 

C++ is great (C++ is my favorite language, and I greatly dislike managed languages) but a good C# programmer is much better than a mediocre C#-and-C++ programmer. Or, a mediocre C#-and-C++ programmer who knows some C.

 

Also, even a mediocre C# will be able to produce a working program faster than a good C++ programmer! The C++ program may run 5% faster overall (or it might not, depending on the implementor's skill!), but usually people will not notice that at all. The C# program will take much longer to start, but people are used to that. You get your stuff out early, though -- which is a marketing advantage. On the other hand, if you plan to get a job where C++ is needed, C# obviously won't get you far.

 

With that said, if you are going to persue C++, you will be surprised that what people consider "good C++" is not that far away from managed code, except you do the management explicitly. You will often/usually use RAII, smart pointers, and containers to the same net effect. The one big difference is you do the "managed" bit explicitly. C++ follows the old philosophy "only pay for what you use", so you are strictly not required to do one or the other thing. It is perfectly "allowed" (not considered good, but allowed) to use raw pointers.

 

You will also notice that the standard library is not as large as the one supplied with C# and it is quite a bit harder to use. No worries, though... it contains everything that you truly need, and you will get used to the usage. It may seem weird at first, but once you get behind its reasoning, you'll see that it's actually quite ingenious.

 

What you should most definitively know about is how to write exception-safe code (read up on RAII and the different types of smart pointers, how they work and what they do, Google and Wikipedia can work wonders for that, even without owning a textbook), the exact workings of the inheritance system, const correctness, and of course, the standard library (you need to understand at least the most important classes and concepts, such as vector, and  map (and know, at least in principle, that there are some others, and roughly what they do -- but in 90% of all cases vector works just fine anyway), how to use iterators, and how to use an algorithm that takes a functor).

Marshall Cline's C++ FAQ has a stunning amount of valuable information that helps you avoid the most stupid mistakes, and it's written in a way one can understand very well, too (in my opinion). Sutter's Mill is a good reading once you feel like you're sitting in the saddle a bit firmer -- probably not for beginners.

Edited by samoth

Share this post


Link to post
Share on other sites

 Thanks for the tips samoth! As a matter of fact I do intent to hopefully land an internship somewhere within the next 1-2 years. Tall order? Maybe but its worth a shot. And I don't mind learning new stuff anyway.

Share this post


Link to post
Share on other sites

If you're new to memory allocation then you'll want to read up on the difference between the heap and the stack, as well as how and why to use each. That will give you a very solid grounding to work from.

Share this post


Link to post
Share on other sites

I've found that learning the "building blocks" of the language to be the most essential in really coming to understand how c++ works. Knowing what pointers are and how they work is a good place to start. You need to know the difference between between allocating memory on the heap and allocating it on the stack and what that means for the scope of a variable or object.

 

When I first started programming in c++ I didn't truly understand the difference between what a reference is and what a pointer is, or I would get myself in trouble by believing my vector or data structure held references to certain objects when they actually just held values(I came from a mostly Java background).

 

My advice is to just sit down and program some of the very basic data structures. Program a linked list, a hash map, a binary tree, etc... Building these data structures in any language will give you an intuitive idea as to how memory is managed. Build your data structures and use them in a small project and use a tool like memcheck to observe any memory leaks. In the future you will likely try to avoid managing your own memory, by using smart pointers and what not, but knowing how to manage memory yourself is really key to understanding c++.

 

Hope this helps!

Edited by DishSoap

Share this post


Link to post
Share on other sites

I have found this to be a decent source for C++

 

http://www.learncpp.com/

 

I've found that learning the "building blocks" of the language to be the most essential in really coming to understand how c++ works. Knowing what pointers are and how they work is a good place to start. You need to know the difference between between allocating memory on the heap and allocating it on the stack and what that means for the scope of a variable or object.

 

When I first started programming in c++ I didn't truly understand the difference between what a reference is and what a pointer is, or I would get myself in trouble by believing my vector or data structure held references to certain objects when they actually just held values(I came from a mostly Java background).

 

My advice is to just sit down and program some of the very basic data structures. Program a linked list, a hash map, a binary tree, etc... Building these data structures in any language will give you an intuitive idea as to how memory is managed. Build your data structures and use them in a small project and use a tool like memcheck to observe any memory leaks. In the future you will likely try to avoid managing your own memory, by using smart pointers and what not, but knowing how to manage memory yourself is really key to understanding c++.

 

Hope this helps!

 

 

Just did a quick look at that site and it follows the same mistake that many (most) C++ books have made.  When C++11 came along ( and even leading up to it ), "good" C++ changed.  Pretty much any resource that doesn't mention RAII within the first few chapters is fail and should be avoided.  These C++ texts that are in their 5th+ revision that simply treated the changes to the language like this site did, by stamping it on at the end, well, they failed.  They are teaching the language poorly out of laziness about wanting to update.

 

C++ has gone through a number of revisions over the years.  Starting as a language built over that compiled into C, then templates, then STL and now C++ 11.  Each of these advances pretty much obsoleted the books that came before it.  That said, you still see tutorials/books that are treating C++ as a better C, using C style string functions for example.  Ditto you see books teaching you naked pointer usage in the first couple chapters.  In the 25+ years C++ has been around, it has changed a great deal...  what I am saying is make sure you are dealing with a learning resource that has been updated to reflect those changes, instead of just bolting them on at the end.

Share this post


Link to post
Share on other sites

Just did a quick look at that site and it follows the same mistake that many (most) C++ books have made.  When C++11 came along ( and even leading up to it ), "good" C++ changed.  Pretty much any resource that doesn't mention RAII within the first few chapters is fail and should be avoided.  These C++ texts that are in their 5th+ revision that simply treated the changes to the language like this site did, by stamping it on at the end, well, they failed.  They are teaching the language poorly out of laziness about wanting to update.

 

C++ has gone through a number of revisions over the years.  Starting as a language built over that compiled into C, then templates, then STL and now C++ 11.  Each of these advances pretty much obsoleted the books that came before it.  That said, you still see tutorials/books that are treating C++ as a better C, using C style string functions for example.  Ditto you see books teaching you naked pointer usage in the first couple chapters.  In the 25+ years C++ has been around, it has changed a great deal...  what I am saying is make sure you are dealing with a learning resource that has been updated to reflect those changes, instead of just bolting them on at the end.

 

 

Good points! 

 

I removed the link. While I don't think it is a bad resource I do agree that it is outdated. 

Share this post


Link to post
Share on other sites

Also, even a mediocre C# (programmer) will be able to produce a working program faster than a good C++ programmer!

 

I feel like that difference shrinks as the caliber of the programmer goes up. Will a really good C++ and C# programmer be appreciably faster when working in C#? Not sure. C++11/14 with extensive use of standard libraries (and good 3rd party libraries) can be very expressive, and also pretty safe if you choose to use a safe coding style (which may or may not come at a performance cost). Certainly it's faster to write some things in C++ compared to e.g. Java, even for a klutz like me.

 

At the low end of skills the difference is the most striking. I think it's accurate to say that a poor C++ programmer will generate negative value to a project. With C++, either plan to get pretty good, or spend your time more constructively with another language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!