from Hacker News

Ask HN: Rust or C or C++ in 2023?

by itsmefaz on 6/6/23, 1:30 AM with 55 comments

Given a choice to learn systems programming or low-level programming in 2023, how would you start?
  • by SAI_Peregrinus on 6/6/23, 3:05 AM

    Learn enough C to encounter the pain points C++ & Rust are trying to solve. C is simple, but not easy.

    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.

  • by 727564797069706 on 6/6/23, 3:54 AM

    As a newcomer to systems programming, I hopped on the Rust hype train and enjoyed the ride for quite a while.

    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

  • by thesuperbigfrog on 6/6/23, 2:14 AM

    C is the best choice to learn systems programming.

    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:

    https://en.wikipedia.org/wiki/The_C_Programming_Language

  • by shicholas on 6/6/23, 2:45 AM

    I would choose Rust because it has much better developer ergonomics than C. Even the little things like having a standard linter and package manager (Cargo) go a long way in writing idiomatic code. You can't go wrong with either choice, so choose the one that makes you most productive.
  • by fargle on 6/6/23, 3:09 AM

    The key to any of embedded, system, or low-level programming is as much about learning how the computer actually works to a reasonable degree. You are not programming to an abstract computation model. You are moving bits and bytes around and generating assembly code and talking to the machine at quite a low-level.

    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.

  • by earthboundkid on 6/6/23, 2:49 AM

    This question is bad. Learn all three. You’re not taking a class at school. There is no penalty for dropping out. Just start learning and if it’s boring, stop.
  • by abnercoimbre on 6/6/23, 3:27 AM

    We have three conference podcasts talking about systems programming in depth:

    - 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-...

  • by debatem1 on 6/6/23, 3:34 AM

    C. It's the only language people writing bootloaders, writing kernels, and writing serious userland code kinda sorta agree on.

    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.

  • by user8501 on 6/6/23, 3:33 AM

    C is forever. It’s the only language where the community aspires to target as early a specification as they can. This keeps C in the hands of the programmers and not the compiler creators.
  • by photochemsyn on 6/6/23, 3:07 AM

    I assume this question is about which language to learn, rather than which language to use for a particular project assuming you're at least somewhat familiar with all three.

    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.

  • by hgs3 on 6/6/23, 2:54 AM

    Try assembly (maybe RISC-V), then C.
  • by andyferris on 6/6/23, 3:41 AM

    For low-level programming in 2023 I would honestly start with Zig.

    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”).

  • by jandrewrogers on 6/6/23, 3:47 AM

    It really depends on the kind of systems programming you are doing. As a rough heuristic, C for embedded because portability across odd silicon; C++ for complex software close to the metal, like database kernels; Rust for somewhat higher level software — not so close to the metal — where performance matters. Right tool for the job, and all that.

    All are good choices in the right context. None is unambiguously superior for all systems programming use cases.

  • by ritchiey on 6/6/23, 4:03 AM

    I'd be interested to hear if anyone has learned Rust without first understanding memory addressing and pointers.

    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.

  • by haolez on 6/6/23, 2:50 AM

    If you are targeting embedded devices, I'd go with C++. If you are targeting super efficient cloud services, I'd go with Rust.
  • by huijzer on 6/6/23, 11:41 AM

    I think learning for the sake of learning is highly overrated in programming. Would a woodworker advice anyone to learn wood working from a book?

    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.

  • by xvilka on 6/6/23, 3:49 AM

    Learn all three but write only Rust unless no choice.
  • by felipellrocha on 6/6/23, 3:02 AM

    Rust
  • by userbinator on 6/6/23, 2:55 AM

    Asm, followed by C89, preferably writing a compiler for the latter --- it's actually not that hard, unlike C++ or Rust.
  • by 29athrowaway on 6/6/23, 3:54 AM

    If you can afford hundreds thousands of dollars worth of static analysis tools, pick C.

    Otherwise go back in time and use Cyclone.

    Or use Ada or Rust.

  • by zabzonk on 6/6/23, 3:24 AM

    rust, c++ and (to a certain extent) c are all quite high level languages. if you want to learn low-level programming, learn it for the assembly language for the processor you are interested in. this will make learing languages like c, and the others easier - i know it did it for me.
  • by pengaru on 6/6/23, 3:37 AM

    C is such a glorious language to competently develop software in, UB be damned.
  • by pajko on 6/6/23, 3:02 AM

    Zig or Nim
  • by nathants on 6/6/23, 3:40 AM

    rust-analyzer, clangd, and clion are all fantastic. why not try both?

    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.

  • by revskill on 6/6/23, 2:57 AM

    Try Rust++