Live data from Hacker News

Hobby x86 kernel written with Zig

github.com

61–70 of 229 posts

Re: Hobby x86 kernel written with Zig

#61
post #51

Earlier quoted context omitted.

As an ancestor in this thread pointed out: it's hard/impossible to go without unsafe in a kernel. Proof (and they have a policy to only use unsafe when not otherwise possible): https://github.com/redox-os/kernel/search?q=unsafe&unscoped_...

yes, that's the point i'm making. saying "if you write your kernel in rust, it will be memory safe" is a little goofy, because writing kernels in rust requires you to drop into unsafe blocks way too often.

As proven by the Oberon and Xerox PARC workstations, the amount of unsafe code is quite minimal.

Source code is available.

Re: Hobby x86 kernel written with Zig

#63
I really wish Zig picks up and goes mainstream. I also wish it gets a little (not too much) of higher level features. Something in line of simple OOP.

I would even start using it now for some smaller projects that are not vital but I was stalled on Zig not being able to compile some C (it claims to do that and it does but not in my cases). Sure I could do import but would rather prefer for Zig feature to work

Re: Hobby x86 kernel written with Zig

#64
post #22

Earlier quoted context omitted.

> I'm asking out of curiosity because I want to learn a "system" programming language If you mean that you don't know any right now, just learn C. This isn't web programming, where everyone is always hopping to the latest fads. C is the lingua franca, the sine qua non of systems programming. It will be a long time before that changes. The C machine model is what everyone is working with anyway. C is small, despite so…

Thank you. I sure tried C too (also C++ for gui programming), though I wouldn't say I "know" it (which to me would imply at the very least one significant real-world experience with it), I do understand why some projects try to modernize "system" programming. I just want to evaluate alternatives, but I may very well go for C in the end...

C is portable assembly, I’d recommend learning it together with the assembly for the platform you’re learning on, so you can actually understand the stack, heap, calling conventions, etc.

Re: Hobby x86 kernel written with Zig

#65
post #46

Earlier quoted context omitted.

you're right, it is confusing, but it is optional: some toy kernels already work in nim , and with latest work on memory, you should be able to use most of the language for kernel development ! not the perfect language for that yet though, but i hope we should see more nim os examples

Are you saying that the GC is optional? If you don't use it how do you allocate/free memory?

Didn't test this but some clues: https://nim-lang.org/docs/gc.html

Then I guess you would use new/dealloc

Re: Hobby x86 kernel written with Zig

#66
post #25

Earlier quoted context omitted.

May I ask why people invent new languages rather than trying to extend or improve existing ones, like C?

You could argue that it's what these languages do, the C heritage is very strong in every one of them. The problem is: do you want to maintain full backcompat or are you willing to break things to do it cleanly? If you do the former you end up with something like C++ which retains almost complete compatibility with C (but they you have a lot of baggage to carry around, which may get in the way at times) or you're wil…

C was already ancient when it came to be.

In retrospective, the aversion of Go designers to current practices in other programming languages is quite similar to the aversion of them back when designing C, versus the other system programming languages that were being developed since 1961, like ESPOL, NEWP, PL/I, PL/S, BLISS.

Re: Hobby x86 kernel written with Zig

#67
post #47

Earlier quoted context omitted.

Nim's GC is optional

How can it be optional if there is lots of code that assumes you are using GC? For example, as far as I can tell the stdlib doesn't do its own allocations. Does this mean you can't use the stdlib with GC disabled? Or am I missing something here?

A friend of mine wrote a DSL for audio using Nim with GC off.

https://github.com/vitreo12/omni

I don't know enough to comment but it may be useful to look at things in the wild. This project also heavily relies on calling in C to interface with environments and the SuperCollider scsynth.

Re: Hobby x86 kernel written with Zig

#68
post #6

Earlier quoted context omitted.

> I used to do this in Rust but I switched to zig for maintainability and readability over Rust. Can you expand on this ? I'm asking out of curiosity because I want to learn a "system" programming language (for whatever definition there is to this term). So far I briefly tried Rust and Nim and found the former more difficult to read. I know nothing about Zig, how would you place it between these two ?

The Road to Zig explains the essence of the language: https://youtu.be/Gv2I7qTux7g C but with the problems fixed.

It doesn't fix use-after-free, double free().

Re: Hobby x86 kernel written with Zig

#69

Earlier quoted context omitted.

Zig is lower level than either (it's more like C than C++: expect to manually call 'free'on allocated values). It has a lot of nice improvments over C however, like proper arrays, no null, a module system, and proper compile time evaluation (no need for the hacky preprocessor).

May I ask why people invent new languages rather than trying to extend or improve existing ones, like C?

> May I ask why people invent new languages rather than trying to extend or improve existing ones, like C?

Because extending or improving a language nearly always means breaking compatibility. Nearly every language is "stuck in a local optimum". To get out of it, you have to kill assumptions of the language that lead to this local optimum.

Also it takes a lot more work to convince other people to adapt my changes than to write an implementation of a language. Add to this the fact that being a good programmer and being a good politician are rather independent skills.

Finally, there do exist issues that cannot be fixed, for example that the official ISO standard of the C language is not freely available (I am aware that there exist drafts in the internet).

Post reply on HN