Monday 5 August 2024

Why I wrote Learn C++ by Example

I recently shared some details about my latest book "Learn C++ by Example".


You can buy my book directly here: http://mng.bz/AdAQ - or just go look at the table of contents. You can also buy it from Amazon: https://amzn.to/4dMJ0aG

There are a lot of C++ books, so why did I write another one? Well, many books delve into the details of a specific language version. As you may know, C++ remained relatively stable until C++11. This felt like a new language in many ways. Some things became easier, for example using a range based for loop meant you can show the contents of a container without needing to learn about iterators first:

#include <iostream>
#include <vector>

int main()
{
    std::vector numbers{1, 3, 5};
    for(auto number : numbers)
    {
        std::cout << number << '\n';
    }
}

Since C++11, there has been a new standard every three years. In fact, the code listing above is now old, because we can use std::println instead of std::cout and import modules rather than include headers. My book didn't cover all the newer features, because I wanted to give just enough to help people get back up to speed. 

My previous blog posts did show what I covered. The chapters have the following titles:

1 Hello again, C++!
2 Containers, iterators, and ranges
3 Input of strings and numbers
4 Time points, duration, and literals
5 Creating and using objects and arrays
6 Smart pointers and polymorphism
7 Associative containers and files
8 Unordered maps and coroutines
9 Parameter packs and std::visit

As I said, this doesn't cover everything. However, I think it gives just enough to help you get back up to speed if you used to know at least some C++, but haven't used the language for a while.

I have been using C++ since the 1990s, along with various other languages. I used to work in finance in London. Trying to get a position can be a challenge. Many organisations give you a thorough grilling, with a homework challenge, possibly a multiple choice "quiz"  and one or more face to face interviews. Aside from implementing linked lists on whiteboards, or spotting missing semicolons on paper printouts, you often get asked about dusty corners of the language, so many people practice and learn a huge number of details about C++. 

I did learn some Python and C# too, which meant I had to take time to revise if I wanted a contract using C++ again. Watching the language change and move would a bit overwhelming, but since I edit ACCU's Overload magazine, I was aware of some newer features I should probably catch up with. Before writing the book I found time to practice some modern C++, and started to form a list of things I knew and things I wanted to learn.

Meanwhile, I sometimes review manuscripts for Manning, and have been a technical proofer for some of their books. I noticed I hadn't seen a C++ book from them for a while. I have a copy of Anthony Williams' C++ Concurrency in Action and recently reviewed a couple of C books. I suggested the need for a short C++ book covering significant changes since C++11 and my proposal was accepted. 

People who have read my book have told me how useful it's been. If you used to know C++, and feel sad because you haven't managed to keep up, don't give up. Find one or two small things and learn those. You might never catch up with all the changes, and C++ will keep evolving. However, you can practice a little once in a while to stop yourself from going completely rusty.