How to learn C++ the easy way!

Many people tell you that you need to learn C++ (or any coding language) the hard way. They mean you need to do examples to really learn the language. What they forget is that when you want to learn a programming language there are often dozens of other tools related to the language that you need to understand how to use to even begin learning said programming language. Trying to learn a topic from several different angles at once is obviously difficult and confusing! Is that error because you didn’t initialize your Visual Studio IDE project or solution correctly? What is the difference between a project and a solution? Is it because of how you set up your folders or maybe because you installed cmake before Visual Studio? Maybe you are missing a library that code snippet depends on? Is #include the same as adding a project dependency? The list of questions someone learning a low level language for the first time has is entirely overwhelming and mostly unnecessary!

Here is my Tip 1 – break your learning down into parts and start with the smallest one. Don’t let someone tell you need to go back to school just because you aren’t yet familiar with their library. The tricky part about learning is you don’t initially know what the smallest part to learn is. So you need a system to keep track of what you need to learn and what depends on what. This system needs to be flexible enough to be updated on the fly, have a zero learning curve (don’t add to the mess!) and give you a structure to base your learning plan on. For me this system also needed to be visual and free.

Enter Trello. Here is my example of starting to write a test Sticky Note program https://trello.com/b/21A8TRRl/sticky. Keep what you are currently working on in an obvious column on the right. Add the dependencies in sorted columns to the left. Drag and drop your tasks as you realize what else you need to learn. This way you can clear your mind and start with one item without worrying about losing your place in that code blog or book.

Tip 2 – When learning C++ start with Notepad++ instead of a full IDE (Integrated Development Environment) and a simple batch file that compiles, links removes your old files and runs your new code easily. This will save you miles of headaches. The batch file code below can be pasted into a .txt file under any name. Change the extension to .bat and you have a valid batch file. To use this simple tool, just drag your .cpp or whatever C++ source code file onto it in order to compile and run. Read the comments to see what it does for you. I have it setup to create a Visual Studio Development Command Prompt (runs a Visual Studio file that sets environment variables) for Visual Studio 2013 on Windows 7. I am using Ultimate version but I don’t think that matters. This allows you to focus on your coding before you need to understand how to setup a project or build for different platforms and whatnot.

Tip 3 – Use a book not the internet! When coding you already have so many tabs open trying to learn each tricky part. It is extremely tempting to just jump back and forth between each tutorial that closely relates to your problem. This will not help you learn and will instead make you feel like you “just can’t get it”. Here is a list of books to save time finding a good one Stack Overflow List of C++ books.

Tip 4  – When learning, ALWAYS make the smallest change possible from what you know works (usually an example) and test that before start including a bunch of other dependencies or customization. Trying to start your first real C++ project while you are learning is incredibly tricky. Starting with what you know and starting with the simplest possible test case is critical to building momentum and actually getting something done. This is a lifelong habit of every programmer! Learn how to isolate areas of uncertainty and apply tests so you know exactly what is or isn’t behaving as you expected/hoped.

Update Real C++ Projects Are Always Hard to Get Started!
I should note to anyone just getting into programming that while learning C++ might be manageable in of itself (especially if you use the method in this article to avoid wasting time), C++ has the added quality of making almost everything as hard as can be. Every library you have to learn and every tool you will need to use inevitably has 100 wrong ways to use it and also many right ways. There are exceptions to every rule and most of the information you will find online is outdated or won’t apply to you directly. I am finding that the trickiest part of real C++ projects is just getting started. Installing libraries and tool kits in the correct order can be important but is rarely documented. Not having certain things installed in combination together is almost always important and even less often documented. If I had to start again I would give myself a few months to gain a working knowledge of C++ and probably another 2-4 weeks for each library or toolkit I found that I needed as well. Ex. C++ 3 months, git 2 weeks, Cmake 3 weeks, Qt Creator 2 weeks, Qt 4-8 weeks. The total then you can expect to be learning (which means coding really slowly) is basically 5-7 months full time. You will always be learning but after that long you should be able to start having some standard for productivity. As you can see, in my case the C++ learning time is only about half of the learning I need to really get going on a real C++ project. In contrast, if you can do something similar with a simpler language that still meets your requirements, learning Python 1 month, PySide 1 month, git 2 weeks, some deploying tool kit probably 2 weeks. So a similar potential project in Python could be about half the learning time. Hope I helped someone plan a bit better than I did when I started! Happy learning.

Batch file text copy starting from the line below this one to the end and paste into a .bat text file to use.
@echo off
REM a comment
echo Steve is compiling linking and running… %1

REM remove .cpp extension
set new_name=%1
set new_name=%new_name:~0,-4%

REM look for .obj and .exe files to delete
if exist %new_name%.obj (
del %new_name%.obj
echo deleted .obj file
)
if exist %new_name%.exe (
del %new_name%.exe
echo deleted .exe file
)
echo.
pause

call “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat”
echo Setup VS 2013 CMD vars and path successfully!
echo.

cl /EHsc /W4 %1

echo compile and link win! Now running… %new_name%
echo.

%new_name%

echo.
echo done
echo.
REM leaves cmd window open so you can see your program output and read the %errorlevel% return value.
cmd /k

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s