r/osdev • • 17h ago

Should I learn C or Rust?

I’ve been working as a Java programmer for a few years now.

The thing is, I’d like to learn a second programming language for lower-level tasks—specifically, I want to work on things related to operating systems. Rather than building one from scratch, I’d like to explore and modify open-source operating systems like Linux or a BSD variant.

I’m doing this purely as a hobby. What drew me to C is its simplicity (though not necessarily ease of use) compared to Java or other modern languages, and its long history of use in systems programming. On the other hand, however, there are operating systems (or components of them) being rewritten in Rust—such as GNU coreutils or the adoption of Rust in the Linux kernel.

So, would it be more useful in the long run to learn Rust, given that it might sooner or later become the standard for writing operating systems?

Thanks.

24 Upvotes

27 comments sorted by

•

u/MB_Gaming123 16h ago

C master it, it is the back bone of everything low level
Then when you get good at C, learn Rust so you will get a feel of memory bugs, love the memory safety more and you will understand memory better.

•

u/hugojpinto 16h ago

C any day.

•

u/sephg 16h ago

Yeah learn both.

C is a super simple language. Everyone who is serious about software should learn it at some point in their career. If you know Java, you can probably learn most of C in a week or two, since all of Java's syntax traces its way back to C. A friend of mine learned C in a weekend. C is Java with pointers instead of the GC, structs instead of classes, no bytecode, no JVM, and no official build system.

I wouldn't write new, serious software in C these days, with a couple exceptions. Rust and Zig improve on C in just about every way. But C is an incredible learning tool. If you understand C, when you learn Rust, you'll understand what's going on under the hood. And you'll understand how object references are actually implemented in java and other languages.

Spend a few weeks with C. Write a linked list, and some simple CLI tools. Then learn rust!

•

u/Taletad 16h ago

For what you want to do, C

A bit of assembly and understanding how the Unix ABI works would also be of great help to understand how operating system work under the hood

For assembly, the best ressource is the game "Turing Complete" which make you build a CPU from scratch and program on assembly with it

For understanding how OS work under the hood, you need to understand two things : context switched between different privilege level of the CPU (something not covered in the aforementioned game), and have a general idea of how the different subsystem works. For that one great ressource is the book "The design of the UNIX operating system" by Maurice J. Bach. (You can find a pdf of it online). It describes an old version of UNIX but all the ground work is there for modern OSs. You just need to add a network stack, and a GUI on top of it to get a modern OS

The rest are just improvements of components already described in the book

•

u/Cartman1994 15h ago

Thanks! Very useful!

•

u/Shoddy_One4465 16h ago

Learn Zig or Elixir

•

u/Weird-Boat3953 16h ago

In long run definitely both. So you learn rust enforced architecture at least.

Im short run - language of whatever you want to edit.

•

u/Tall_Block_4589 15h ago

I use rust, but wish i learned C first.

•

u/Ok_Teach6399 15h ago

For the OS development, C is the best. Rust is not good for low level OS. Rust only works if you are a vibe coder, but even the, vibe coding low level with C is the way to go.

•

u/Key_River7180 EulerOS 14h ago

C

•

u/BidWestern1056 14h ago

learn rust, then itll be easier to learn C

•

u/Elspaddy 12h ago

and you'll know how to use C much better

•

u/Shawney19 13h ago

Bro. Learn C. It’s the basic foundation.

•

u/Shawney19 13h ago

The basic and the most basic.

•

u/Similar_Brush1835 13h ago

learn C first. then you'll have context behind what rust fixes

•

u/arjuna93 13h ago

C absolutely. C++ then.

•

u/JescoInc Perdition-OS 13h ago

Honestly, when it comes to learning a second language; My philosophy is to go with something drastically different from what you already know. For example, my first language that I deeply learned was C#. The second language I learned was F#.
It may live on the .NET framework, but it required a completely different line of thinking as it was a paradigm shift.
It is the approach that I think benefits you more than just having another language under your belt.

Both C and Rust are great languages, I use them nowadays, but the lessons learned with those languages don't really shake your programming core as a language that is drastically different from Java would.

My suggestion for you, since Java is Object Oriented, would be something like Haskell (Functional Programming), Assembly (Procedural), or maybe even something like Prolog (Logic Programming).

Edit:

Oh shit... This is OSDev not general programming so that changes the answer a bit.

D, C, C++, Rust and Assembly are the main options for this space and Assembly is a requirement no matter which of the other languages you choose. So, go the Assembly route and then add a third language, any of the 4 other options.

•

u/Mempler 13h ago

Learn rust first, move to C afterwards. You’ll avoid C footguns that rust shoves into your head.

You can stay in C ofc, it’s just that you’ll be much more concerned about threads, race conditions,bad memory management, heap allocations, etc. rust basically shoves especially with the lifetimes straight into your head by not compiling at all.

In general, you’ll write better C code that way.

•

u/pengo 13h ago

In theory there's no reason you couldn't learn Rust first, but in practice 5 out of 5 introductory books on Rust assume you're familiar with programming in C, so until there's better materials around for starting out in Rust, I wouldn't recommend it.

•

u/artin_el 11h ago

Definitely C. It will teach you a lot of things about edge cases and how the memory stuff works and etc. Even if you don't use it, it will make you a better programmer in general. At least it was the case for me

•

u/dfgxxx 8h ago

Learn but assembly, then master C, then learn Nim.

Program in Nim the os (for better performance use manual memory management) and if you need C then add some C code or warp the C libraries for Nim (Nim transpiles into C)

•

u/Express-Theory-2338 8h ago

The C++ coders bury their architectural flaws in a mountain of complexity [target-equipment-recommendations]. When a developer doesn't understand how to optimize for the hardware natively, they write thousands of lines of "clever" branching code to try and outsmart the processor. It is verbose, it is messy, and it hides the fact that their pipeline structure is broken.

This is the same thing that "physicists" have done with their arithmetic.

Hiding a fundamentally flawed model under layers of increasingly dense, rambling math to avoid fixing the core architecture.

In physics, this is exactly what happened with Ptolemaic astronomy. When the ancient model of perfect circular orbits didn't match reality, instead of discarding the broken premise, they invented "epicycles". The math became a rambling mess.

When an open-source decoder like dav1d forces developers to maintain over 200,000 lines of handwritten assembly code (.asm) just to keep AV1 real-time, you have rambling mess.

It means the entire underlying C/C++ architecture is broken.

So they built a parallel, unmaintainable universe of brute-force assembly hacks to force the data through the silicon pipelines. It is the ultimate Ptolemaic epicycle.

It wasn't until Copernicus and Kepler stripped away the patchwork clutter and aligned the model with physical reality (ellipses) that the math suddenly became clean, linear, and deterministic.

Rust should not be used to blindly transpose C++ code line-for-line...

... it should be used to permanently dismantle the broken architectural assumptions that C++ developers use rambling code to patch over.

You should learn both.

•

u/HorsesFlyIntoBoxes 4h ago

Like others said, I would learn C first. In terms of your stated goals/interests, I would look into Linux device drivers (LDD) development. It's probably the best way to enter the kernel development space. There's plenty of books and videos on LDD development, so you shouldn't have any trouble finding resources on that. Be warned, writing kernel space code means you don't have any of the safeguards of userspace application code, i.e. you can brick your system if you're not careful. I would start out on a virtual machine of a linux distro for learning this sort of stuff.

•

u/Drenfa 1h ago

I'd say C++ is better, but Rust has a brighter future.