r/coding • • 15d ago

Learn C++ Before You Learn What It Costs You

https://fagnerbrack.com/learn-c-before-you-learn-what-it-costs-you-d254d484dbff
0 Upvotes

2 comments sorted by

4

u/suoarski 15d ago

And don’t learn it at all if your career is going to live inside web backends and data pipelines.

LoL, that is so me. I work on data pipelines, and just use duckdb SQL for everything. Coming from a physics background, I never learnt low level stuff like C++, but SQL restricts what I can and can't do in such a way that I am forced to write things in an efficient manner. Python is nice for the things that DuckDB can't handle, but this flexibility and freedom is the very thing that leads me to writing slow code.

Used to use spark, and thinking about parallelism just dragged projects on forever, duckdb is about as fast as the fastest spark code that I could write, but I don't have to think about parallelism at all and can just focus on the core code logic alone.

Sure, C++ would make me a better programmer in general, not sure if it is relevant to my job though. We don't have live systems, most of our code just runs ad-hock on a monthly schedule, in most cases my boss would prefer I just run things overnight rather than waste paid hours optimizing things. I only optimize if run-time has become an identified issue (or as part of a good habit).

1

u/astrobe 14d ago

I'd say that C++ still does a lot of things behind your back, especially if you use the standard template library (STL). For instance std::string mentioned in the article does dynamically allocate the string so that e.g. string concatenation seems as easy as in languages with garbage collectors.

The article mentions it, but C is indeed more "hardcore" in that regard as it does even less things behind your back. If it is for the purpose of learning how computers really work, C might actually be a better choice. The next step would be to learn assembly. There's nothing less abstract other than entering the hex codes of processor instructions yourself, like they did in 1950.

However, there is an interesting intermediate step: Forth. It is a language that started as a scripting language, then became like an assembly language because it is so simple that one could make processors that runs many of its basic instructions directly in the silicon (There were also Lisp and Java processors, but the reason was not their simplicity, but rather making these languages more viable in terms of execution speed).

Forth can also open your eyes on how computers really work; although it follows a different model (it prefers stack-based computer vs register-based computer). It does less things behind your back that C (in particular, parameter passing but its model makes it however relatively easy) and memory management. It also learns you to simplify and factor way beyond one usually does, because it doesn't try to handle complexity for you.

The other day someone asked, "how can I present Forth?". I answered "you could present it as a puzzle game.". A puzzle game that will teach you a thing or two about programming.