When should you choose C++ as your starting language?
Table of Contents
When I’m lurking through the internet, I often see posts asking about “what language should I pick as a beginner???”. As someone who struggled a lot with this choice, and ultimately picked C++ (for reasons that made no real sense—but, of course, I didn’t know that back then), I think I can say a few words about this specific choice and how it can affect the learning process of an individual.
It’s a trap!#
TL;DR of this post - it’s usually not a good idea to pick C++ as your starting language. After working with C++ for a long time, and tasting many different programming languages, I feel like C++ is a convoluted mess taped together using subpar-quality duct tape, somehow still holding on, maybe even going in a relatively good direction with recent changes, but certainly not good enough for a beginner to learn the programming principles on at its current state.
Why would you even want to do that?#
Excellent question! In most cases, I hear these specific arguments, trying very hard to justify picking C++ as a starter:
- It’s very fast!—very common misconception. Languages are not inherently fast nor slow. Sure, some languages can be parsed or interpreted, faster than others, but it does not imply that a program written in language A will always be faster than a program written in language B, or vice versa. Surely, that can be a thing - we absolutely can write a program in C++ that will be faster than an equivalent program in Python or Java, but it works both ways! A good practice is asking yourself “why?” and “when?”. Why a program written in language
A
may be faster/slower than an equivalent program written in languageB
? And at what scale does it become meaningful to performance? But that’s not something that a newbie should care about. Generally speaking, you should NOT care about “language performance” as a beginner, as it’s one of the last things you’ll have to worry about when learning programming. In the beginning, the real performance will lie mostly in data structures and algorithms used in your code, not the language choice. - Learning C++ teaches you low-level concepts, like pointers and manual memory management! It can, but there’s a biiiiiig but. You don’t have to know these low-level concepts to write software and learn programming. Every day thousands of programmers write perfectly fine and working code without even knowing what a pointer is, or how to manually manage the memory. It’s not something that you absolutely must know in order to write working code. It’s not something that may ever be useful for you. I certainly agree with people saying that knowing how pointers and manual memory management work can be useful in many situations, but for a beginner—it’s certainly not a must-know, as even in C++ you usually don’t want to manually manage raw pointers and memory allocations.
- Game programming is done in C++—usually paired with the “much performance” argument—is also invalid, as there are plenty of very popular game engines that provide a much more newbie-friendly approach to game development. Check out Godot as one of the best examples, since it has both its own toolset that uses its own GDScript language, but also can be used with other languages and tools if you prefer that approach or you already know them and don’t want to learn new stuff. I know there are plenty of people doing gamedev in C++, and they do have a point in that—being relatively close to the hardware it’s not the worst choice of a language, but I still strongly believe that it’s an overkill if you want to learn “programming” and “game development”, as it carries a heavy bag of “having to learn C++” before learning the stuff you really wanna learn. Don’t forget that, if you’re thinking that it’ll be a breeze and something you’ll do “on the side”, you may lack some crucial knowledge. Of course, if you wanna do it “raw” and really refuse to use existing game engines, you absolutely can do it in any language that has some kind of multimedia API… so, basically, the most available and popular languages for sane people (brainfuck btfo). If you don’t believe me, this game was written in Pascal, from scratch, in 2017. And it runs great!
- I know some C, so C++ is just an extension, so I’ll learn it. It is not, and thinking that way will force you onto a path from which it’s very hard to return, as I have witnessed multiple times with my own eyes. Beware of thinking about C++ as an addition to C, as it’s just as foolish as thinking about a dragon being an addition to his precious mountain of gold. You WILL get burned. You WILL witness horrors beyond your comprehension. That last part is also true when talking about C++ in general. Compare the following articles with their C counterparts (the link is at the bottom of the reference page) and rethink your life choices.
That list may become longer with time.
So, what are the alternatives?#
Another excellent question! Loving the audience today.
Obviously, I will have to answer according to my own opinions and beliefs, however, I will also try to explain why I think like I think I think. I think that will make it easier to, at least, continue your research. Remember - t̴h̴e̶ ̷r̷e̵s̷e̴a̸r̸c̴h̸ ̸n̷e̷v̸e̷r̷ ̷e̵n̵d̴s̸.
- Python: Some people will tell you that Python sucks. Some people will tell you that Python is not a good language for beginners. Some people are wrong and cannot comprehend the simplicity and beauty of whitespace-defined syntax. I, however, will tell you that I love Python because it rarely disappoints me. I need to write a simple tool that does some stuff automatically, and I want it to work everywhere? Python is my guy. Its long support, big community, package manager, and existing tools are making it very hard for me not to recommend this language as a starter. The syntax is sure very specific, some might even say exotic, but after working with it for a while it annoys me only sometimes when I have to move a block of code to a different place and manually fix every indent. And it even has type hints and easy-to-use tools that’ll make sure you adhere to typing rules, which some people may find very useful. For a beginner though, you’ll most likely want to focus on the vast PyPI repository to write some useful stuff for yourself. Its documentation is also relatively decent and even has a tutorial to get you started, but if you’re completely new to the IT and/or programming world I’d recommend looking for a first-time tutorial more suited to your level of knowledge, as the “official” one is not very newbie-oriented.
- JavaScript (or maybe even TypeScript?): It’s a very simple gateway to the vast world of web applications, but not only, as you can plug JavaScript almost anywhere nowadays… I’m personally not a fan of this language, but from what I’ve seen - people who start from JavaScript have a certain “freedom” of being able to use this language anywhere they want, which is nice if you don’t know what you exactly want to do yet, but usually comes with additional baggage of tools for creating user interfaces - HTML and CSS being the usual ones, but most likely also paired with some fancy frameworks and other funky stuff that—according to many web developers—are needed to write functional pages, for which more elegant technologies from simpler times may be more than enough). I’m getting out of topic though, I endorse JavaScript as a starter way more than I endorse C++, but be aware of many pitfalls this language comes with. Which can be said about basically any language, but the Big Dev won’t tell you about that!
- Kotlin: If you want to learn Java for whatever god-forsaken reason you may have, don’t learn Java—learn Kotlin instead! If you wanna make Android apps and you’d rather use official tools than some webdev mumbo-jumbo, Kotlin is your guy! Its Java legacy makes it a reasonably good starting language, as you have both a nice, modern language with nice, modern syntax and useful features that are simply a joy to work with, and a vast repository of libraries, some written long before Kotlin even existed. I haven’t worked much with this language, but I enjoyed almost every moment of it.
- C: Yeah, let’s put it on the list, why not. You wanna have a very close relationship with your hardware? Here’s your language. Don’t tell me I didn’t warn you though. In all fairness, C is certainly lacking—real generics, for example, but that doesn’t stop people from using it even right now. As a language to get the hang of programming and “how does stuff work under the hood” it’s a great choice, as a language to write working applications without having to create a whole universe beforehand… not so much, unless you work on something that does not require an entire universe to run, but I will get to it soon. I promise.
This list is by no means comprehensive. There are a lot of languages that are deemed “reasonable for beginners” that are not on this list, just because I either never worked with them, or worked so long ago that I cannot assume that my knowledge is still applicable to its current state (e.g. C#, which I’d like to say something about, but I really can’t).
Notice that my focus here is to recommend a language that will be relatively easy to learn and easy to use, with a big community and lots of resources to learn from—C++ is lacking in many of these aspects, which makes learning modern C++ the “correct” way surprisingly hard. And, to be fair, it makes doing anything in C++ unreasonably convoluted and painful. Ever tried to set up a C++ project from scratch with automatic unit and integration tests? I did. And failed. Not because it’s impossible, but because I simply rather choose a language that supports that stuff out-of-the-box (unit testing, at least). And I’ve seen projects that do have this stuff in C++, and I… uhh… I’d rather avoid having to jump through the hoops of CMake and similar tools in order to have stuff that’s relatively easy to do in other languages usually without having to learn how to use 3rd party tools. And there’s C, as a direct C++ alternative, and I’ll explain why it’s here—because it’s certainly not for the same reason as other languages on this list.
When it actually makes sense to go C++ head-first#
As with any rules, there are exceptions, and this includes my “No C++ for beginners allowed” rule.
The most obvious exception for me is targeting embedded programming as the thing you want to do. And it’s also the reason why C is on my list - because C is much simpler than C++, it might be a better idea to start with that instead. But if you wanna use Arduino, like most beginners nowadays, sticking only to C makes little sense as there are powerful and relatively easy-to-use features of C++ that you already have access to (and might have to use, depending on the libraries you work with). Sure, you may not have the standard library and its fancy features (and I’d argue that it’s a good thing), but you still have the power of templates, lambda expressions, constexpr, and many more cool features. So yeah, if you wanna tinker with hardware then learning C++ might be unavoidable for you.
But only might—if you ignore the existence of Arduino framework—not the hardware, the hardware is its own thing and it’s just a “brand” name - you may just stick to pure C and write the code from scratch directly for the microcontroller you have, or using vendor-provided tools (like STM32CubeIDE for ST microcontrollers). However, this is substantially harder as it usually requires you to actually read the documentation of hardware you’re working on. It’s really not something for faint-hearted developers that would rather stick to copying and pasting random pieces of code from the internet or ChatGPT, with the hope that it’ll solve all their issues.
Another obvious scenario is “you have to learn it because of school/university/work/side-project I’m doing with some C++ developers”. Or you may just be very, very, very fiercely and weirdly focused on learning C++. For that, I have no cure. I just have a tip: try to stick to modern sources and don’t get sucked by outdated, pre-C++11 tutorials and books that have questionable reputation. There are many. There are curated lists of sources from which you can start your journey.
And I can’t really think about any other scenarios where C++ would really make sense. Some time ago I’d say that OS-dev is a good niche for that, but you can do OS-dev in C as well, and there’s Rust for the cool kids that sit on the back of the bus—much saner choice than C++ if you ask me. Borrow checker may go hard, but it’s there and will never leave you. Do you want the same commitment from C or C++? Configure it yourself. And it won’t be half as good as what Rust does for your code. Graphics programming and game development? Yea, sure, maybe. Maybe if you are new in this world, still with hopes for a better tomorrow, still young and innocent, it will sound like a good choice - and you may even walk through this path relatively unscathed. But then again, you may not. I’d still look at alternatives first, just because lots of people do it in C++, doesn’t mean that you have to do it in C++ too.
I may sound like a big C++ hater, but to be honest, it earned it. I’ve spent years with that language, and half of this time I’ve spent fighting with it. Do I regret it? I regret not jumping this ship earlier, but I’d say that lots of things I’ve learned via C++ I’ve found useful at some point. Could I learn those things while focusing on different languages? Some of them, yes, but not all of them. Would I go a different path if I could start my journey again? Fuck yes, I’d jump straight to Python or webdev, but considering my areas of interests and expertise I’d end up with C++ at some point anyway.
I’m also not saying that C++ should never be learned or used. It’s got its things going, and with a certain amount of experience in general programming and with setting up software projects, it’s possible to work with it. But you need that experience and knowledge first, and head-slamming into a C++ wall may not help you get that knowledge in comparison with other available methods.