Hello
I have been thinking about starting over, mainly so I can do things differently, but also to support multiple platforms, for start x86_64. I am thinking it might be easier to redo the base of my os rather than fix the mess that it is, and so I am thinking also about the language I will write in.
Lately a few of you have been developing in Rust. I've looked at the site and installed it, but I don't really understand why it's better, other than it's the new cool thing.
It said something about memory safety. or something. I'm just wondering if there is really any reason to learn Rust to make an OS with other than the academic reason (ie. something new to learn)
Ideally I'd write an os in JAVA (that's my favourite language) but, in reality unless I go with Rust, it'll probably be C.
Andrew
Rust OS Development
Re: Rust OS Development
Rust runs at the same level as C or C++, whereas getting Java to run like that takes a lot of work. Its memory safety comes from static analysis instead of a garbage collector- the compiler tracks references to objects and ensures that they can't last any longer than the object itself, and that mutation only happens with exclusive access to the data.
Things that don't match that pattern, like reference counted objects or shared-memory concurrency primitives, are implemented in libraries by marking pieces of code as "unsafe" and then hiding them behind an interface that uses the type system to make sure they're only used correctly.
When writing an OS, you'll end up writing a lot of that "unsafe" code yourself, so you don't gain quite as much as you would if you were writing applications, it's still a big help to isolate those pieces where you know they can't be misused.
But besides all the memory safety stuff, Rust also has a lot of nice features compared to C or C++- modules instead of header files, trait-based generics instead of templates and virtual functions, pattern matching instead of unions, affine types instead of copy/move constructors (and RAII instead of C's manual resource management).
Overall, I'd say Rust is a fantastic language for writing an OS, where you need a lot of direct control over the hardware, and you're writing a lot of critical infrastructure code, but you don't necessarily need a lot of access to existing APIs (Rust can speak C ABIs, but is relatively new and so doesn't have a lot of bindings you'd expect yet for writing applications).
Things that don't match that pattern, like reference counted objects or shared-memory concurrency primitives, are implemented in libraries by marking pieces of code as "unsafe" and then hiding them behind an interface that uses the type system to make sure they're only used correctly.
When writing an OS, you'll end up writing a lot of that "unsafe" code yourself, so you don't gain quite as much as you would if you were writing applications, it's still a big help to isolate those pieces where you know they can't be misused.
But besides all the memory safety stuff, Rust also has a lot of nice features compared to C or C++- modules instead of header files, trait-based generics instead of templates and virtual functions, pattern matching instead of unions, affine types instead of copy/move constructors (and RAII instead of C's manual resource management).
Overall, I'd say Rust is a fantastic language for writing an OS, where you need a lot of direct control over the hardware, and you're writing a lot of critical infrastructure code, but you don't necessarily need a lot of access to existing APIs (Rust can speak C ABIs, but is relatively new and so doesn't have a lot of bindings you'd expect yet for writing applications).
Re: Rust OS Development
Apart from the memory model, which is of course the main Rust feature, there are also a few constructs that help protect against bugs.
Exhaustive pattern matching is one, and I found quite a few places where the newtype pattern comes in handy (e.g. to distinguish between physical and virtual addresses in the kernel).
Also, the core library has been stabilized recently and has all kinds of things a freestanding environment needs. You don't have to reimplement things like formatted output, for instance.
I've kept a close eye on emerging systems languages for a few years now, and in my personal opinion Rust is the best thing that happened there in the last decade, at least.
Exhaustive pattern matching is one, and I found quite a few places where the newtype pattern comes in handy (e.g. to distinguish between physical and virtual addresses in the kernel).
Also, the core library has been stabilized recently and has all kinds of things a freestanding environment needs. You don't have to reimplement things like formatted output, for instance.
I've kept a close eye on emerging systems languages for a few years now, and in my personal opinion Rust is the best thing that happened there in the last decade, at least.
Re: Rust OS Development
It seems you want to pick the "coolest" language. But unfortunately it's completely up to you to decide on the issue of the language that is the best for you.apamment wrote:Ideally I'd write an os in JAVA (that's my favourite language) but, in reality unless I go with Rust, it'll probably be C.
I like Java and have the OS written in Java just because I don't like the complication involved with the C programming. And if I want to pick a language then I just play with it until I see if it suits me. So, you should play with Rust and only then it will be possible to decide if it is good for you.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability
Re: Rust OS Development
Java is the coolest language? I had no idea..embryo2 wrote:It seems you want to pick the "coolest" language. But unfortunately it's completely up to you to decide on the issue of the language that is the best for you.apamment wrote:Ideally I'd write an os in JAVA (that's my favourite language) but, in reality unless I go with Rust, it'll probably be C.
That's nice.embryo2 wrote:I like Java and have the OS written in Java just because I don't like the complication involved with the C programming. And if I want to pick a language then I just play with it until I see if it suits me. So, you should play with Rust and only then it will be possible to decide if it is good for you.
Of course it's completely up to me to decide what language I write in, but I don't think there is anything wrong in asking other people who are already knowledgeable on the subject their thoughts.
Thanks Rusky and Icee for your posts. They were very informative.