I begun to write this two years ago at the beginning of the pandemic, but then forgot to read, and hit publish. I think today is a good day to update, clean up, and publish.
You might not be stranded at home anymore, but I think most of the things I wrote are still valid, I had a couple of extra things to say, and I have a much more reasonable conclusion to it.
So here it is, the (quite long) story of how I studied C++. It won’t have much pointer to material, so don’t read it if you’re looking for that.
You’re born in 2000, went through a couple of global crisis without even noticing, got stuck at home, decided you wanted to be a game developer, and realised that without some C++ knowledge you won’t go too far, so you decided learn it.
Cheer up, you couldn’t be in a better place! Depending on where you are, you might be still stranded at home, and you can spend hours and hours in front of a computer trying to divine compiler errors, without losing much of your life: you shouldn’t or couldn’t get out too much anyway, what better way to learn something while avoiding a terrible virus?
Let’s make it clear, learning C++ is difficult. Very. That’s why I don’t trust much those books or courses who claim to teach you C++ in few hours or days.
Keep in mind, I haven’t read those books. Most of them weren’t available when I was studying C++ anyway. They might even be great books, but I find the title misleading: you won’t learn C++ in 24h, and not even in 21 days.
That said, books aren’t useless, and I imagine a few people will comment this post saying that this or that book had a strong impact on them. I hope they will.
I used a few tools to learn C++, but your mileage may (and will) vary a lot.
I can hear your question: “At the end of the day, how long does it take to learn C++?” I gave my answer already a couple of time in my talks: It takes the same amount of time it would take to properly learn how to play Sitar. And so, here it comes the real title of this post.
Teach yourself C++ in 7 reincarnations
I’m not saying you should follow my path exactly, and I’m actually pretty sure you can do better: there’s a lot of people younger than me that are already know C++ better than I do. But this is how I got here… it’s interesting to watch things in retrospective, every once in a while.
In your first life, you’ll code C++ for yourself
I started learning C++ in 1995, more or less at your age. At that time, resources weren’t easily available, I had no book, just a couple of examples and access to Italian FidoNet programming area (and the demoscene area too – but that’s where I learnt cursing in C++, mostly).
I spent the following two years working on a real-time raytracer.
Yes you read it correctly, I did real-time raytracing in the mid ’90s, but it wasn’t the fancy and cool graphics you have in mind with games such as Cyberpunk 2077, Battlefield V, or Shadow of the Tomb Raider. Not even like Minecraft RTX.
Mine was in a variable resolution from 80×50 to 160×100 (depending on the scene complexity) and ran at 10fps or less, on a Pentium running at 166MHz (without MMX). The scene you could produce with the first version consisted of just spheres and planes (but had multiple light sources, reflections, textures, and horribly-looking bump-mapping). I used the same technique for a while, releasing two other 64K intro.
Actually I was neither the only one to achieve that, nor the first one to do something similar: in the demoscene alone, somebody from finland did it in 1995, and some others from Italy beat me by a couple of months.
That book opened my mind: until then I was treating C++ as a glorified C, but C++ had much much more. I also bought a green book about STL, but couldn’t make much sense of it at the time, as most of the compilers had no support for it, and in those who had it was quite poor anyway.
Meanwhile internet started growing and became easily available in my university, at home via dial-up modems, and then via ADSL. I could access more and more resources, and started growing my knowledge, but still keeping it for my small projects. C++ remained my favorite language for all my fun in my demoscene life (that lasted at least until 2008, if not now), but in my part-time day job, the one I did to pay for my university, I was a Visual Basic and Java developer.
In your second life, you’ll code C++ for someone else (and they will probably hate you)
With the help of my Image and Sound Processing professors, I managed to meet Enrico (more on him later), who was among the founders of one of the most amazing companies I had ever seen back then, Phoenix Tools.
I really wanted to join as an intern, even if I had almost 5 years of professional experience, working in other languages (mostly Visual Basic and Java, but occasionally some Pascal and Assembly). Luckily they kindly disagreed, and decided I could join as a part-time developer directly, with a more than decent salary for the time.
And here I did my novice mistake: I started running. I wanted to show off my cool C++ tricks, and so I ended up putting everything I knew in there, and for that reason I was the only one who could read that code.
I imagine the poor folks that ended maintaining that code (my manager Stefano and the colleague Max), had an hard time extirpating all the templates and the compatibility library that would (in theory) have allowed to backport those shaders back to mental ray (like anybody wanted to do that), or to simplify the porting to other platforms later (again, quite unlikely, and potentially inefficient, due to the limited capability of compilers back then).
I left the company few weeks before the release, while they were growing and moving to new offices. The plan was to leave for one year, because I had to serve my country, and when I came back, ready to claim back a place in that company, I found out that it went bankrupt in the dot-com bubble.
Max recently joined at the company I’m currently working for, and claimed to have no memory about that code… Maybe it wasn’t that bad after all, but it could also be a polite way to avoid saying how much he hated it, or a way to cope with the trauma of dealing with such a bad code. Hi Max :)
In your third life, you’ll code C++ for serious stuff (which will probably not work)
I was still to finish my university, and my plan wasn’t to abandon it anyway, so I decided it was a good opportunity to go back to my professor and got a degree quickly, which I did in a three-year long master thesis work, studying how to accelerate beam tracing with visibility information, and its application to virtual acoustics in 2D and 2.5D (not exactly the “quick” route you was thinking, huh?).
I designed my simulator entirely in C++, trying to follow all the best design choices, picking up the standard library and using it as best as I could. I was working with Microsoft Visual Studio 6.0 and the first Visual Studio.net, and both didn’t have a good support of the standard library, so I learned of an amazing project called STLPort by that genius of Boris, with whom I had the honour to work with, few years ago at my current employer.
Reaching the limits of C++ and STL I started looking at boost, and then, in order to make sense of those mysterious errors (that were mostly due to my bad coding), I learned of static analysers, and started using them more and more.
I also spent the two years after my graduation writing the draft of some papers that my professor inevitably re-wrote from scratch, a patent that I still can’t read, and trying to extend my method (and the code), to handle the full blown 3D case, learning crazy things like geometric algebra in the process, and helping to debug code for some other inventions from the same team, such as the Binary Connection Tree method Giovanni developed. This were two awesome years, because of the all people I met there (too many to list, but more on some of them later), but they were also terribly frustrating years, during which I learned a few things in what I think was the hardest way possible (i.e. crashing into walls):
- even if you can manipulate things in five dimensions, it doesn’t mean that you’re going to do it efficiently
- floating point numbers are evil, and they will bite you in many different ways
- I proudly discovery of the worst method for sorting points counterclockwise (yeah, floating point involved here).
- I took months to discover bugs on someone else’s code. Turns out that
new int(5)are two different things, but under certain conditions (font and size) they look very similar.
- Did I mention floating point number are evil? Well, I didn’t even started talking about
NaN, and peaks of CPU usage in audio processing for no apparent reasons, something that can be solved by adding and subtracting a very small number (this might not happen anymore in modern processors, but at the time it was a real pain).
In your fourth life, you’ll become an architect (and you will learn that code is sticky)
Given that we weren’t going anywhere, with my professor we agreed to move on to something different. At the time, there was a project in the lab working on facial recognition, and they needed an engineer to create a product out of some experimental code developed by Luca (a fellow researcher in the same lab, who is actually one of the best prototypers I’ve ever met). They really wanted me to take that super-efficient mess of code and turn it into a nice-looking, well-maintainable, well-behaving, portable C++ code, a dream.
At the time, it’s 2005, I’ve been working in C++ for almost 10 years, and professionally for 6 of them, but I was still doing Visual Basic from time to time for the same company I’ve worked since 1996 (more on that on the next life, too). Sticky code.
Maybe it’s a good moment to make a digression: code is sticky, this taught me one important lesson: you don’t want your code to be too bad, it will swing back, probably in your face.
But before that, something else hit my face.
I happily worked on this face recognition library for a couple of years, and then created a company with Luca: I felt this was a good idea, as our business model was similar.
The company was a huge success, we managed to have, among the others, three of the biggest customers we could think of at the time: the biggest telephone company in Italy, the most important private television group, and the motorsport division of a well-known car manufacturer.
As I said, with Luca we had a similar business model in mind, but turned out our ideal customer wasn’t the same, so we split the company after two years. I would say we split it exactly in half, because of the three big customers one stayed with me, one with Luca, and on the last one we worked together.
And then the Subprime mortgage crisis came. Of course, this crisis wasn’t directly related to my area, so I didn’t even see it coming. Actually, I even managed to gain something from that at the beginning, as I received some fantastic loan conditions.
Because of the crisis, my biggest customer canceled half of their orders in 2009, and my oldest customer (the one that basically paid for my university) went into trouble and eventually hit bankrupt few months later. So I got a loan at fantastic conditions (which I still have to pay), but I was also paying some unexpected consequences of splitting the company (insanely high taxes), and the unexpected lack of income didn’t make it an happy time. I was literally counting the cents in my bank account.
Luckily for me, Enrico (the one from Phoenix Tools) reached out, and was in contact with an industrial group that was interested in acquiring a small software consultancy firm. I made the agreement, started hiring back people, and working again at full steam again.
The face recognition startup (now a proper spinoff) was still my customer I managed to move away from being their principal architect, and got more involved in their “special projects”, like porting their library to embedded platforms and other exotic projects.
That’s when Google got in touch with me, because sometimes good things happen when you least expect them. This was so unexpected that the first email I read from them said “Just checking to see if you received my previous mail and if you would be interested to hear of opportunities at Google”, followed by an email from a couple of months before, that I completely missed.
They wanted to interview me. I had a phone screening and went in (or I should say “came to”) Zürich for an onsite interview. The interview went well. Very well. A lucky strike, I would say, because one interviewer asked me exactly the two things I had done in the week before the interview, while porting the face recognition library to an embedded platform: implementing an integer arithmetic square root, and extracting a uniform sample of fixed size from a sequence of unknown length in a single pass. I should probably write something about these two problems in the future.
I almost got an offer, but I realised I couldn’t do it in the timeframe they wanted. I made some promises to a couple of new hires, and signed a binding agreement with the industrial group, and I didn’t wanted to leave people who believed in me after just a few months. Google interviewed me another couple of times, but I never passed the onsite interviews again.
And then the face recognition also went broke, but fortunately another C++ library with many other language binding needed to be ported from java and maintained for a few years, and then I even ended up working on nuclear security for the research group with the coolest name ever.
Before joining my current company, I even went back to the facial recognition library again one last time. Yes, the company went bankrupt in 2013, but two new companies bought the code, and one in particular needed to gain some knowledge on the codebase. Code is THAT sticky.
But here we need to go back to the end of my third life, because there was another one starting at the same time.
In your fifth life, you’ll be one of “those who can’t do”
“Those who can, do; those who can’t, teach.”
I’m not sure who said that, but wasn’t definitely an happy person. Teaching is fun, and while teaching you learn a lot of skills.
I started teaching programming when the Italian Ministry of Public Education needed teachers to teach high-school teachers a new language called Java. Why did I knew Java in the first place, and why was I, as a university student, in the position to be a “teacher for teachers”? Well, turns out that one of my customers heard of this new language when it was still in beta, and paid me to learn it. At the same time, as part of the community, we created an association of java developers in Italy. Via a series of unpredictable events, I turned out in front of an audience of teachers which, if possible, is the worst audience ever for teaching.
But soon enough, my university also needed laboratory teachers for C/C++ (yes, exactly “C slash C++”, like the two languages had anything in common except some basic syntax).
Being a laboratory teacher is even more interesting than teaching in class. You see how people reason on a problem in real-time, what fallacies are hidden behind our simplified mental models, you learn to read the code quickly and find silly mistakes, often very well hidden, even when they don’t produce any warning; you learn some of the nastiest quirks of C++, and finally you learn that you shouldn’t teach “C slash C++” anymore (some slides are in English, but talks are all in Italian – if you don’t understand it, you can have a lot of fun with the Engrish automatic subtitles, and trying to guess what I’m really saying).
I had some seminars in English too, but unfortunately none was recorded and published, because they were mostly held for private audiences. You can still find most of the ideas and content in this very blog, and I promise some day I’ll also try to organise my slides and post them here. I started collecting them in a folder on my computer a few years ago, so there are chances that this will happen one day.
In your sixth life, you’ll be one of “those who can’t teach“
In Fidonet all “emails” contained what was called “a tagline”, a punch-line written after your signature, and I remember one in particular that recited: “Those who can do, those who can’t do, teach, and those who can’t teach, manage.”
I managed the company I started for most of my time there, but never enjoyed it too much. Back in my own company I was directly involved with ALL the projects, and I felt very much like if I ever left, the projects would have gone terribly bad. And being not that good at financial management, going bad would have meant I wouldn’t be able to pay for my own very convenient loan. The stress was too high, and I risked a burnout multiple times. Once, to avoid burnout, I had to take an holiday, and disappear completely for two weeks in Egypt without a phone (where I became a scuba diver, but that’s another story).
Now it’s different, I’m a technical manager, and I feel more like a glorified team leader than an actual manager. But I won’t discuss this life too much, as it’s still developing under my feet. This has even changed in the two years between the first draft of this article and the publishing date, as I was forced to become a remote manager, and realised I could still be a remote manager even when this pandemic will be over.
In your seventh life, you’ll join the Enlightened (and you’ll receive a terrible impostor syndrome in exchange)
Disclaimer: “you’ll join Enlightened” doesn’t mean you’ll be Enlightened yourself. I hope you will, but I don’t feel like I am.
Even more recently (slowly, from 2011 until now), I started following more and more the work of the ISO C++ Committee, I talked to conferences, and even started writing a proposal that very few have seen coming, and a couple of years ago – together with some fellow members of the Italian C++ Community members (Volker, Federico, Vittorio, Marco, Davide, Eugenio, and Franco) – we created the Italian Delegation to the ISO C++ Committee (ISO/IEC JTC1/SC22/WG21).
And if the previous life was still developing, this one has literally just begun, and I already feel terribly unprepared.
I’m not sure there is one, or if any of this made any sense to you.
Maybe the thing I could say is that I didn’t plan for any of this. It just happened. Maybe this is the real suggestion I can give: let things happen.
As you probably realised, I lived seven overlapping reincarnations, and none of them is complete.
All this is still a work in progress, seven fractions of the things that, I believe, are needed to learn C++ to a proper level. Having spent half of my current life on it, and being roughly halfway through my own life, I’d say I just need another 130-150 years of this to reach my goal.
As final proof that no life has been lived completely, I recently went back to the first one, the time when I was writing C++ just for myself. One of the things I enjoyed at the time was what I called “the bubble”: the lack of distraction – being alone with the machine, and having to solve problems on your own (no internet back then, remember). I tried to recreate those moments, but I have changed, and the entire society has changed too. Now we’re constantly connected, we receive notifications, and those notification are a constant distraction for me. Social media is a distraction too. I tried turning off the phone, and disconnect from the internet, but it didn’t work.
So I had to be creative, and found a nice way to exploit the “connectivity” to remove most of the toxic distractions: a way to recreate a bubble. Not “the bubble”, that is lost in time and won’t come back, but something that help myself to remain focused on C++. I stream my coding sessions on Twitch. It’s a bit counterintuitive, and I didn’t expected that to happen when I started: by being connected, I know I might have someone that is looking at me and is expecting me to write some C++, do something meaningful with it, and possibly explain what I’m doing. Sometimes they have specific questions or suggestions on what I do, sometimes they ask you if they should learn C++, sometimes they just learn by watching, and are mostly silent. This audience, or sometimes is just the idea of a potential audience, is what currently help me to remain focused.
Well, if you got here, thank you for reading. If you’re one of the person I mentioned and you want your name to appear in full, or one that I should have mentioned but I forgot to, or if you think I should clarify some parts, just reach out to me.