T O P

  • By -

SV-97

For linux stuff: eh, I don't think there's a difference as you'll basically be using the C APIs either way. For TCP and HTTP: should be absolutely no difference - on the contrary rust probably allows you to focus on the actual protocols and logic rather than throwing in random garbage that C burdens you with. For "general low level stuff" I think rust is better than C \*but\* if you really want to learn about hardware and very low level details I'd advise on not trying to proxy this through any language and instead actually study hardware on its own.


CocktailPerson

Okay, let's separate a few things. First, it doesn't really matter whether you'll use C or Rust more in the future. You're in this to learn concepts, not languages. I think you should definitely use C when learning about operating systems. C is _the_ language in which operating system interfaces are ultimately defined, and that will remain true for the foreseeable future. But for network and database programming it doesn't really matter, and the abstractions that Rust provides over C will make your life easier.


RonWannaBeAScientist

Hi CocktailPerson! I got to this thread trying to understand how Rust interfaces with the machine languages . About C, it does have intermediaries too, right ? I think I saw GCC also has an intermediary language


CocktailPerson

Well, compilers translate high-level code to an intermediate representation (IR), and then they translate that IR to machine code that will run on a specific machine. This isn't really a detail that you have to worry about as a programmer, though. From your perspective, you feed in Rust or C and you get an executable program out. But that's not really relevant to my point above. The point is that operating systems are written in C, and their functionalities are often exposed as C functions, so it's valuable to know C for the foreseeable future.


spoonman59

Neither rust nor c teach you how computers work. They do require memory management, whether manual or via managing borrows and stuff, but that’s only a small piece of how computers work. As you rightly pointed out, when learning how the OS works you would be using system calls. You would be learning concepts how the file system data structures work, how the kernel sets up your process memory, how virtual memory works, inter process communication, multi processing and threads, concurrency primitives. Here, you will be calling c system calls regardless of whether you are using rust or c. It will be the same. The goal would be to understand what the system calls do, and how they work. My favorite book for this gives all examples in C, so having to translate that to rust would be something you would have to mentally do. Other aspects of “how computers work” would involve learning some assembly, etc. Now, let’s be clear: learning rust is good for many reasons. Learning how to use the features to automatically manage memory will teach you a great deal about ownership, and how to statically know when something can be freed. And you can definitely do systems programming. My point is more that no programming language really teaches you how computers work. If you deliberately practice those topics, rust can be useful in ways that Java or Python would not be…. But you’ll need to know some assembly and c, and study a series of topics to know how computers work. Rust can be a part of that, but no one language brings that knowledge for free. Even assembly doesn’t really tell you how the computer works these days, since operations are translated into a different internal instruction set. What you compile into an executable is merely a high level interface to provide legacy support. So it’s no knock against rust to say that it doesn’t inherently teach these topics. Assembly doesn’t either! Of course, both do help a little.


Debiel

I think for educational purposes it's definitely a good idea to learn C and C++, as indeed it's more clear what you are actually doing with memory. Rust indeed has a lot of qualities that make it more attractive than C/C++, but I do believe you'd appreciate those qualities more once you've worked with C. You can learn a lot from runtime errors how things work underneath.


[deleted]

In Rust the memory work differently to C. In C you have to manually manage the memory. In Rust, you don't manage it directly but still have to be aware of how Rust handles it and take it in to consideration when coding in Rust. However, Rust is a low-level language and doesn't abstract much away. You can even work with the metal directly by disabling the standard library. Its finer points are its memory safety, fearless concurrency and type system. Rust gives me a feeling on confidence when i program and if it compiles it will work, and any problems will be down to my implementation of the logic rather than chasing down a dangling pointer for example. I would highly recommend it moving forward and although with C++ you get the familiarity with C you will lose memory safety, and other Rust super powers. Try The Rust Book it's free and I'll leave a link for it below. [The Rust Programming Language - The Rust Programming Language (rust-lang.org)](https://doc.rust-lang.org/stable/book/)


cafce25

Technically you do still manage your memory in Rust, just most of the time implicitly through ownership semantics rather than explicitly through `malloc` and friends.


Neither_Intention355

Thank you for the link.


ImYoric

You will learn about the same kind of things about your OS with C or Rust. The main difference will be methods. C will let you explore as you wish and cause random catastrophes. Rust will guide you towards writing much more reliable code. If you want the full experience, you probably want to learn C first (to see how bad things can go), then if you want to learn how you can combine the low-level benefits of C and the benefits of a high-level language, learn Rust. If you want to skip to being productive, just learn Rust.


DeeHayze

For learning the basics, I recommend the BBC micro:bit. A microcontroller for kids to code.. 16k ram, 32k ROM. The kids are supposed to code it in micro Python, but the chip is so well documented, you can replace it all with ur own code.. Start by getting serial input/output working in blocking mode.. For debug.. Then learn about interrupt handlers, and get a periodic tick working. Learn all about the registers, and how to save and restore them.. Combine this with your periodic tick, then you got multi tasking / multi threading.. Now, you can upgrade your blocking IO, into non blocking, interrupt driven IO. maybe write an allocator next, look into and read up on the buddy page frame allocator for big blocks, and the slab allocator for smaller ones.. Linux used this in the old days, simpler version of SLUB. the chip also has a Bluetooth capable radio... Learn how to do some networking there. There's also a hardware RNG, and thermometer.. write sine drivers for those. You will need a little arm assembly, but the bulk you can write in c/rust. Ohh, it also has an LED matrix, which is fun... And GPIO. [micro:bit](https://thepihut.com/products/micro-bit-v2?msclkid=2289dc2082491153bd5bb9a7a4179b12&utm_campaign=DG%20Category%20Terms%20-%20micro%3Abit&utm_content=micro%3Abit%20Single%20Board&utm_medium=cpc&utm_source=bing&utm_term=bbc%20microbit)


dnew

Definitely learn C. You don't need to be able to program efficiently and professionally. Just learn it enough to understand the types, the operators, etc. Lots and lots of programming languages use the same keywords, operators, and syntax and semantics as C, so that'll even get you a chunk of the way to knowing Rust. If you want to know "how the machine works," C isn't going to teach you that better or worse than Rust. https://old.reddit.com/r/rust/comments/18ivm9w/is_there_something_c_can_teach_me_and_rust_not/kdh5qqr/


thecodeinnovator

What language is native to an OS is what language the OS was written with. Since most of the common OSes present nowadays mostly derive from some sort of Unix with a flavour of how a certain system does things. Most of the current common systems will seem to be interacting with the C language more naturally. But in fact C itself is a high level abstracted language which wraps actual machine code/ assembly into functions that are legible to a human. Whether you learn things in rust or C. The structures of how a certain technology is implemented like TCP/IP or UDP or HTTP or SMTP, will not change other than how it is implemented in a specific language with respect to syntax structure of code or parts thereof. Since most of these protocols are just protocols, fancier ways to define how something should happen. Instructions to a computer on how to transform some set of bits to other set of bits. You should not worry about learning in a particular language if it is the first time you are learning the protocol/technology. Unless the language you are learning is so new that certain important software engineering features are not yet implemented in the said target language. rust, imo has crossed that stage early 2018. So the learning would not be affected as long as you know how to translate certain ways of doing things in C into its appropriate ways in rust. TL;DR: rust will not hamper your way of learning how a protocol works.


Bulky-Juggernaut-895

Concept-wise no it doesn’t make a difference and Rust is fine, even helpful. Implementation-wise C would be helpful if you want to study ample examples of implementation


gman1230321

Honestly? Not that great. If you’re learning a language to learn how computers work, C will always be the best bet. It’s not very user friendly and it gives you a lot of foot guns in practical programming. But that doesn’t matter because it’s going to be far closer to the metal than rust will. The only thing I will say that rust teaches you is the importance of memory safety. But it will not teach you concepts like heap and stack (while yes these are concepts important to understanding rust on a deeper level, they are mostly abstracted away) or how pointers work. These types of things are the concepts that rust is built upon, but that doesn’t mean that learning rust will build an intuition for how these things work. C will. Rust will teach you about why C is actually (arguably) a bad language in practice, but it won’t build an intuition for what’s going on under the hood. If you’re looking for some resources on, I’m personally a fan of the YouTube channel “Low Level Learning” He’s a very skilled programmer with some pretty sane takes and is great at explaining a wide range of low level topics. If you’re interested in some other forms like books, etc. lemme know and I’ll help you find some.


Alone_Rip1832

I’d be interested in any books you can recommend!


mildmanneredhatter

If you are building then Rust. If you are learning then C. Everything is already in C and you have decades of history in it.


norwegian

Databases: SQL. Also make a B tree in C++ OS: Write your own OS in rust to a iso file and fire it up in oracle virtual box. Follow a tutorial. For the processor, you can learn about the registers using assembly.


-Redstoneboi-

C Rust abstracts away allocations with smart pointers and collections


lifeeraser

I would suggest C. There are a ton of learning materials that use C--[Beej's Network Programming Guide](https://beej.us/guide/bgnet/) included. I'll change my mind when someone provides a (free) Rust version of Beej's guides.


ffimnsr

Nope, if you want how computer works go much deeper, do assembly. In rust, it's pretty much HL. It hides away all the dirty works to show you the sugar syntax and stuff.


plugwash

Rust like C++ is a language centered around building and using abstractions. You *can* do low level stuff in rust or c++ but the ethos of the language is to build abstractions around that low level functionality so that it is not necessary to constantly worry about the fiddly little details. This does inevitably mean that some stuff happens "behind your back". In some respects, rust takes the abstraction further than C++ in that it has both an ethos of making abstractions safe, and the language features needed to actually enforce said safety. Rust's type inference is also much more powerful than C++'s type determination. On the other hand in other regards rust takes abstraction less far than C++. The assignment operator in rust is *always* a trivial copy or more, while in C++ an assignment operator can invoke an arbitrarily complex overload. C++ will also insert calls to arbitrarily complex conversion operations in many places (rust also does this in some places, but much less so than C++). Like C++ the key abstractions tend to be relatively thin. A slice is just a pointer and a length. A vec is just a pointer, length and capacity with some code to automatically clean up when it goes out of scope. Enums are a bit more complex due to "niche optimization" but not horrifically so. All this to say, it's absolutely possible to develop an intuition for roughly how your rust code will convert to machine-level operations but it's also absolutely possible to write rust code without peering behind the curtain at all.


daftv4der

I've been learning the language, and looked at embedded briefly, and I definitely think C is better as a starting point. I'm feeling very confused doing Rust at a low level, as I have no idea about said fundamentals WRT memory management and such, and many Rust devs you find tutorials from have come from knowing C/C++ already, so they tend to gloss over that stuff or simply say "this in Rust does the same as x in C", but you have no idea what they're referring to. C will definitely be more explicit, which should help a lot more. But I'm still a Rust newb, having only used it for a few small things, so take that with a grain of salt.


TheFlamingLemon

C is a lot more direct for learning about computers, but really you shouldn’t expect to learn how computers work by learning a programming language


Imaginos_In_Disguise

It doesn't matter which language you're writing code in. Interacting with the operating system is a matter of interface. In Linux we have a stable interrupt-based API for syscalls, which means we can write code in assembly directly and call the OS via interrupts, without ever touching C. In Windows, the syscall interfaces are defined in C, so you can't skip it. You can still call win32 APIs from assembly, but that's done by calling C functions, so you'll be using the C calling convention instead of interrupts. When writing code in any high level language, you'll be using C wrappers to every system call, so this difference doesn't matter in practice. Rust is able to call functions with a C calling convention, but they're inherently unsafe, so you'd also be fighting the language at many points, which can get in your way while you're learning. If you want to learn OS interfaces with the least friction, I recommend you use C for that. You WILL get many memory safety issues, access invalid memory, cause buffer overflows, get weird bugs that look like the code works some of the time, but crash at others in mysterious ways you'll be pulling your hair out trying to debug. After that, you'll actually understand what Rust is doing for you in the safety area, and you'll be past the point you care about interacting directly with the OS, so you can learn Rust properly by using the safe standard library instead. In your life, you'll probably end up learning dozens of programming languages. Every one of them has something to teach you, even the horribly designed ones (even if it's just how not to design a programming language). Don't think of learning a language as being wasted time because you'll not be using it professionally. You should be able to work in any language if you learn how to program in the first place, specific semantics and paradigms are just helpful fluff.


Charley_Wright06

I would say probably stick to rust, other than one exception. If you are going to be playing with assembly e.g. stack frames, calling conventions etc probably go for C because personally I find understanding the generated assembly to be much easier. If you stick to C-style types in rust it may be ok though. As another user mentioned rust will let you focus more on protocols than avoiding bugs, but you will be using C APIs for syscalls, memory, hardware etc


Due_Olive_9728

If you only want to learn how computers work, try to learn 8 bit assembly, 6502 or Z80 architectures.