5 ms·
If you're starting a new operating system project, you might consider using Zig[1] instead of C. It does all the low level stuff that C does but it has some sa
by AndyKelley 9y ago
If you're starting a new operating system project, you might consider using Zig[1] instead of C.
It does all the low level stuff that C does but it has some safety features as well as generics.
The standard library is usable in freestanding mode, even the data structures that allocate memory, because everything takes an allocator as a parameter.
Here are some examples:
* i386 OS: https://github.com/AndreaOrru/zen https://github.com/AndreaOrru/zen
* ARM (raspberry pi) OS: https://github.com/andrewrk/clashos https://github.com/andrewrk/clashos
[1]: http://ziglang.org/ http://ziglang.org/
- derefr 9y agoWhy not Rust? Or, say, Ada?
- panic 9y agoOr go all the way and design a new language too!
- qznc 9y agoAh, the Knuthian approach. Why not go more than all the way and design an architecture too?
- pjmlp 9y agoThat would be to just use Assembly, given Mix.
- snaky 9y agoAssembler is too high level these days. This would be translator from higher languages to hardware. http://conal.net/papers/compiling-to-categories/ http://conal.net/papers/compiling-to-categories/ https://icfp17.sigplan.org/event/icfp-2017-papers-kami-a-platform-for-high-level-parametric-hardware-specification-and-its-modular-verification https://icfp17.sigplan.org/event/icfp-2017-papers-kami-a-pla...
- pjmlp 9y agoThanks for the reading material, quite interesting. I think you are right, recently I saw an Arduino-like projects book, but using VHDL instead, which somehow pointed into this direction.
- mveety 9y agoI don't know if this is my conservatism speaking or not, but one problem I see with this approach is that you wouldn't learn as much because more batteries are included. Having to implement more than just a kernel (like the standard library and userland) gives you more of a chance to learn intangibles like what is or isn't appropriate to include in an API or what programs will actually be useful given your overall design. Also, there could be the problem of not having as many resources available in the language you're writing your OS in. That's a huge deal for a less experienced programmer. That all being said, Zig looks pretty okay. It would be a good candidate to write an OS if you had to because the standard library looks trivially portable so you could test the userland on a known working kernel before getting it working on your new kernel.
- dom96 9y agoAs an alternative to this you could use Nim[1] which compiles to C. If you, like myself, dislike C, Nim can be used as a "better C" (you can disable the Nim GC and forget about its standard library, then use Nim as a thin layer over C with modules, generics and other nice goodies) 1 - https://nim-lang.org/ https://nim-lang.org/
- NetOpWibby 9y agoI’ve been wanting to learn how to use a real programming language (I’m strictly front-end languages) and Nim looks great at first glance.
- pjmlp 9y agoOther point of view, would be to consider that the language runtime is the OS being implemented.
- snaky 9y agoThere is ATS for the task, with all the C features plus proofs, quantified constraints, dependent types, linear types, interface for pluggable SAT solvers and so much more. https://bluishcoder.co.nz/tags/ats/index.html https://bluishcoder.co.nz/tags/ats/index.html
- earenndil 9y agoApparently this is the shill-c-alternatives thread. Here's a short list: * Rust * D * Zig * C2 * Nim * LISP * Ante * Clay Please note: I think all of the above languages (with the exception of C2) are awesome and should be looked at.
- cbHXBY1D 9y ago* Myrddin * Terra
- pjmlp 9y agoYou forgot - Ada - SPARK - Modula-2 - Modula-2+ - Modula-3 - Oberon - Oberon-2 - Oberon-07 - Component Pascal - Active Oberon - Dylan - Object Pascal - Sing# - System C# - Swift - C++ (assuming C++17) Then the older than C, or about the same age. - ESPOL - NEWP - PL/I - PL/M - PL/S - PL/8 - Mesa - Mesa/Cedar - Algol68-W These are the most well known ones. Plenty of material to learn for anyone that anyone with interest in systems programming and how it evolved since 1960.
- earenndil 9y agoI'm talking about legit languages people are proposing to replace C with that are actually any good (except C2, it was an afterthought and I regret it because it was out of place and unlike the other languages there purposeless). Ada and perhaps C++17 is the only language people are actually recommending to replace C.
- pjmlp 9y agoYeah, given the current market situation, you are right. However, there are quite a few lessons on the manuals, papers and sample code from those languages, to learn about other approaches of doing systems programing. Lessons that one can bring back to life. For example, are you aware that ESPOL, the systems programming language for the Burroughs B5500 in 1961, about 10 years before C was created, already had the concept of UNSAFE code blocks? Burroughs B5500 is still sold nowadays as Unisys ClearPath mainframe. Or that IBM implemented their research OS and compiler toolchain for their very first RISC processor in PL/8, a safe systems programming language, using a compiler architecture similar to how LLVM looks like? IBM mainframes still use PL/I variants, although new systems code is a mix of C and C++. So plenty of ideas there to learn, even if no one is going to start writing new code in those languages. > Ada and perhaps C++17 is the only language people are actually recommending to replace C. I would still add Swift to that list, even if that turns out to be just like Objective-C, mainly specific to Apple platforms. Given Apple's roadmap for it.
- jsandler18 9y agoWhen I started this, I considered writing it I rust. However, I really wanted this to be the tutorial I would have wanted to read several years ago when I first developed an interest in OS, and a "modern" system language like zig or rust would have hurt that goal.
- mkesper 9y agoBecause real programmers don't use such tools?
- jsandler18 9y agoWhat? No. Because way more people know C than rust. I wanted to be able to reach a wider audience. I know I would have looked elsewhere if I saw found this but I didn't know the language.