Then learn enough Rust to be productive.
Then learn enough C++ to interact with the enormous amounts of existing C++ code.
Once you know a bit of all 3, decide where to focus based on the work you're trying to do. Rust is the easiest, but least widely supported. C is necessary either way, unless you're working for Microsoft where C++ fills that role.
I think I know what you're trying to say, but unfortunately C is anything but simple. The semantics are riddled with surprises of all kinds. It's unlikely the average C programmer has never written a program with undefined behavior, for example.
Rust hurts when you're learning it. C hurts when you're trying to debug your program.
If you've never written low level code before, I wouldn't start with rust. Zig or C are both much better options when getting started. But learning rust eventually will make you a better programmer.
I'd add that the average C programmer can't spot UBs before they cause a problem, they are not your average bug. Unless you're very well read or are just told about them, that is.
But in recent months, I've been more drawn to Zig. Simplicity, vision and governance of the language (among many other things) are very much to my liking.
As a bonus, I can use Zig to interact with C (even compile C, Zig is also a toolchain), so I feel I'm bound to learn more about C on this journey, too.
In your position, I'd also check out Zig, just to see if it's more your cup of tea or not. Here's a good intro talk: https://youtu.be/YXrb-DqsBNU
C is the simplest of C, C++, or Rust and most other languages have C interop or foreign function interface.
First learn C and then you can learn Rust or C++ if needed. The concepts you learn in C programming will help you to better understand the more advanced concepts used in Rust or C++.
Recommended first book:
So, IMO worth jumping to Rust as soon as you feel confident with the stack vs the heap, use-after-frees, etc.
I mean, why would I expect the parenthesised subtraction to do anything I can rely on? Or did you mean (&ys[2] - &ys[0]) ?
C forces you to think like a programmer. Once you grasp that, you can learn most other languages with relative ease.
Maybe not counting Lisps.
The rust programmers that learned C first always have very elegant solutions and have the least issues in their unsafe blocks.
C to learn how memory works and how to manage resources, then Rust to understand how to use a higher level systems language for more productivity in places where it helps.
I work as a C++ dev and there are jobs in it, but unless you are trying to work a C++ job, the other two are wayyy better.
C knowledge also helps to understand what rust's borrow checker is actually doing. And it will teach you what Box / Rc / etc are for. Its surprisingly easy to write rust code that Box everywhere, and runs very slowly in practice. (I've seen rust programs run slower than their javascript equivalents). Learning C first will give you the right knowledge base to appreciate rust and use it well.
However, it is not a productive systems programming language these days compared to C++, Rust, or Zig.
So while Rust and C++ are higher-level languages with all kinds of nice features to be safer, concise, structured, etc. they are not good at all for learning how to work at this low-level. Wielding either of them well for systems code is quite advanced.
C and assembly are where you really need to start.
C++ is the de facto “most performant” language for a reason.
passing structs to functions is probably the way, but a struct with functions works too.
- The Race to Replace C & C++ (2020) [0]
- The Race to Replace C & C++, Episode 2 (2021) [1]
- Memory Strategies: The Merits of (Un)safe (2022) [2]
They feature prominent guests including the creators of Zig and Odin, as well as people making a living using Rust. Hope this helps!
[0] https://handmade.network/podcast/ep/fe1a2a6a-3ac6-4ce5-b8fb-...
[1] https://handmade.network/podcast/ep/57103cab-ff39-42b4-b59b-...
[2] https://handmade.network/podcast/ep/afc72ed0-f05f-4bee-a658-...
Maybe someday it'll be rust, but if so that day isn't this year or next. Plenty of time to pick it up for your next job.
C++ is not a bad place to start, as any decent course in it will, after the basic concepts of variables, loops, arrays, functions, pointers and memory, algorithms & data structures, introduce you to both classes and inheritance and encapsulation (the typical object-oriented paradigm) as well as how to write functions with nested lambdas (the basic functional paradigm). From there you can pick up almost any 'higher-level' language like Java, Python, etc. that utilizes some kind of virtual machine/interpreter to run the code, the various pure functional languages and so on.
Learning C and/or Rust is then a lot more accessible I think. You'll have some grasp of why 'memory-safe' Rust became fairly popular, and of why C's more low-level and simpler approach (no classes, inheritance, etc.) relying on structs, function pointers, etc. instead is still attractive, flaws and all.
The underlying theme though is that these languages all compile directly without any Python-like 'bytecode' intermediate, so probably at some point diving into the assembly output for specific platforms (x86-64, ARM, RISC-V) will be worthwhile, for which godbolt.org is the place to go.
It offers the same system programming capabilities as C but makes it much easier to write correct programs.
(If Rust is the “better C++”, then Zig is the “better C”).
All are good choices in the right context. None is unambiguously superior for all systems programming use cases.
Although I think Rust is a better way to write safe code and the industry is right to adopt it, it seems like a heavy lift to learn about heaps, stacks and pointers whilst also learning about ownership and lifetimes.
I don't really think that C++ is worth learning unless you have to work on an existing C++ codebase.
Find a project that you think is important and work on it. Doesn’t matter which language. You can always switch. Knowing C++ will make you a better Rust programmer and vice versa.
Otherwise go back in time and use Cyclone.
Or use Ada or Rust.
cpp feels better to me now, but that could easily change.
rust-analyzer is a good experience, and cpp is not exactly fast, just faster.