Readplace

Learn C++ Before You Learn What It Costs You

fagnerbrack.com 5 min read
View original
  • best
Summary (TL;DR)
C++ changes how you read other languages by making hidden costs visible. A simple Python print hides heap allocation, reference counting, and locking, while C++ exposes references, copies, temporaries, and buffer management. C++ teaches manual memory, value versus reference semantics, and abstraction costs, like reallocation in push_back or pointer chases in virtual calls. This knowledge becomes permanent pattern recognition, helping you write faster code but also creating friction when reading idiomatic higher-level code. Learn C++ early before habits form, but skip it if your career stays in web backends where the machine is hidden on purpose.

Learn C++ Before You Learn What It Costs You

The language that gives you a perspective that doesn’t age

5 hours ago

A line of "console.log" code as an iceberg tip with machinery below the surface

C++ is worth learning. The catch is that it changes how you read every other language for the rest of your life. Besides, you don't get to choose which parts of that change to keep.

Most advice about C++ stops at the first sentence of that paragraph. The standard pitch says: "it teaches how computers really work", and then hands over a copy of Stroustrup and wishes luck with the template errors.

The last 2 sentences rarely get to the sales pitch. 5 years into a Python/Java/JS job, you’re still flinching at things your coworkers can’t see.

Here’s the example I give to anyone who asks what they’d gain.

def greet(name):
print(f"Hello, {name}")

greet("Jess")

void greet(const std::string& name) {
std::cout << "Hello, " << name << "\n";
}

greet("Jess");

A Python/Java/JS programmer reads the first one and sees a function that prints a greeting. That’s the right reading, because nothing in the code asks for anything else.

A C++ programmer reads the second one and can spot many decisions.

The string comes in by reference rather than by value, so no copy happens at the call site, and the const in front of it is a promise to the caller that the function won't touch their data. The parameter is a std::string, but "Jess" isn't one, so the compiler builds a temporary std::string just to bind it to that reference, and the temporary lives until the end of the full expression.

Then there’s the line that prints.

std::cout isn't a function. It's a global object that owns a buffer sitting between the program and the terminal, and writing to it moves bytes into that buffer rather than onto the screen.

<< is the left-shift operator, the one that shifts bits. C++ lets you overload operators, so the standard library handed << a second job on streams. Each << in that line is not a string concatenation, it's a function call that writes one thing to the stream and returns the stream, which is the only reason 3 of them chain left to right. The compiler picks a different operator<< for the literal than for the std::string, and it picks both before the program runs.

The "\n" at the end puts a character in the buffer and stops. std::endl would put the same character in and then push the buffer out to the operating system. In a loop running a million times, that difference is measured in seconds.

The first version is shorter. The C++ version teaches you what the first one hides.

Now read the Python version again with C++ eyes, not Java eyes, cause you don't want to have to wear glasses (Java devs can't C# 🥁).

The string is a heap-allocated object with a reference count that gets bumped on the way into the function. The f-string allocates a second object and copies both halves into it, and the print call takes a lock on stdout before a single character moves.

You can’t see any of it, but it runs on every call.

This is the trade.

C++ teaches things that no other mainstream language does (at least not as deeply), and once you learn them, it's hard to unlearn.

The first is manual memory. Every other popular language ships a garbage collector, a borrow checker, or a reference count, and lets the programmer forget that objects live somewhere physical. C is the exception, and it teaches manual memory more bluntly than C++ does, with no destructors and no smart pointers to soften it, but it just stops there.

The second is the gap between value and reference semantics. In Python every variable is a label tied to an object, while in C++ a variable can be the thing itself, a pointer, or a reference to it. All these behave differently in every copy, assignment, and function call, and a whole class of senior-level bugs comes from not knowing which of them is in play.

The third is the cost of abstraction. A push_back can reallocate and copy every element it already holds. A virtual call costs a pointer chase, and a std::function heap-allocates for any capture that doesn't fit inline (and few do).

C++ doesn't hide these things.

You can’t understand code without seeing them.

I’ve heard senior engineers say “C++ ruined me for Python” and laugh. The way people laugh at things that are true.

But how does one language ruin you for another? Basically through a layer of pattern-recognition that you can't turn off. The knowledge built over a few years of C++ comes along into every language after it.

You see allocations in list comprehensions. Copies hide inside function arguments and stand out anyway. A Pandas operation registers as expensive before you’ve measured anything.

This is sometimes a superpower. You write faster Python than the people around you, not through tricks, but through avoiding shapes that are expensive on sight. You know which abstractions are free and which ones will generate long term debt.

The same benefit is also a cost.

You read clean, idiomatic, perfectly fine code and have to suppress the urge to rewrite it. You watch a coworker pass a 50MB dictionary through 3 function layers and feel something deep inside, even though Python just passed a pointer and nothing moved… I’ve spent years training myself to shut up about it in languages where the cost doesn’t matter to an extent I don't really care anymore.

So here’s the recommendation:

Learn C++ early, before your habits set and before an identity forms around a higher-level language. Spend some time with it outside work, write something that manages its own memory, and read Effective C++ until you feel personally attacked.

Don’t pick it up as a third or fourth language after a decade of Python or JavaScript, because the pattern-recognition still arrives but it arrives as friction. The energy goes into fighting the urge to rewrite code that doesn’t need rewriting.

And don’t learn it at all if your career is going to live inside web backends and data pipelines, where the runtime hides the machine on purpose. That’s paying the price and collecting none of the benefits.

Learning a language teaches you to write it.

Learning C++ teaches you to read every other language differently…

… for the rest of your life.

If you liked this, you might like readplace.com, built for exactly this kind of reading.

Thanks for reading. If you have some feedback, reach out to me on LinkedIn, Reddit or by replying to this post.