Zig self hosted compiler is now capable of building itself
41–50 of 285 posts
Re: Zig self hosted compiler is now capable of building itself
#42Hello HN! Here is some context to decorate this announcement: The Zig self-hosted compiler codebase consists of 197,549 lines of code. There are several different backends, each at varying levels of completion. Here is how many behavior tests are passing: LLVM: 1101/1138 (97%) WASM: 919/1138 (81%) C: 740/1138 (65%) x86_64: 725/1138 (64%) arm: 490/1138 (43%) aarch64: 411/1138 (36%) As you might guess, the one that thi…
> written in Zig instead of C++, uses significantly less memory, and represents a modest performance improvement That's particularly interesting considering the rust compiler in rust has never been as fast as the original OCaml one
Re: Zig self hosted compiler is now capable of building itself
#43I was thinking of learning Rust but it seems a bit overkill due to manual memory management as compared to languages with similar speed like Nim, Zig, and Crystal. How would one compare these languages? Is it worth learning Rust or Zig and dealing with the borrow checker or manual memory management in general, or are GC languages like Nim or Crystal good enough? I'm not doing any embedded programming by the way, just…
Zig uses manual memory management too (even more manual than Rust), so that's a bit strange question.
Re: Zig self hosted compiler is now capable of building itself
#44Earlier quoted context omitted.
Zig uses manual memory management too (even more manual than Rust), so that's a bit strange question.
Interesting, based on their code samples it looked to me like a GC language since (at least from what I saw) I didn't see anything regarding memory management.
Re: Zig self hosted compiler is now capable of building itself
#45Earlier quoted context omitted.
Memory has to be managed by something. The more decisions that are made for you in how that happens the less flexibility there is for certain situations.
Sure but my use cases would be stuff I'd normally write in TypeScript or Python that already have garbage collection. Like I said I'm not doing embedded programming so I don't have too much of a need to manage memory. My question could be further constrained then to be, is learning Rust or Zig despite its manual memory management worth it for applications that are normally already garbage collected in their current i…
Re: Zig self hosted compiler is now capable of building itself
#46Re: Zig self hosted compiler is now capable of building itself
#47Re: Zig self hosted compiler is now capable of building itself
#48Earlier quoted context omitted.
Memory has to be managed by something. The more decisions that are made for you in how that happens the less flexibility there is for certain situations.
Sure but my use cases would be stuff I'd normally write in TypeScript or Python that already have garbage collection. Like I said I'm not doing embedded programming so I don't have too much of a need to manage memory. My question could be further constrained then to be, is learning Rust or Zig despite its manual memory management worth it for applications that are normally already garbage collected in their current i…
Zig has no garbage collection btw, but makes it easier than C to handle that. Another language without garbage collection that helps a lot to avoid memory issues is Ada (Looks a bit like Pascal). So there are alternatives to Rust.
Re: Zig self hosted compiler is now capable of building itself
#49I was thinking of learning Rust but it seems a bit overkill due to manual memory management as compared to languages with similar speed like Nim, Zig, and Crystal. How would one compare these languages? Is it worth learning Rust or Zig and dealing with the borrow checker or manual memory management in general, or are GC languages like Nim or Crystal good enough? I'm not doing any embedded programming by the way, just…
> Is it worth learning
Languages are easy to pick up once you understand fundamentals. The borrow checker is intuitive if you have an understanding of stack frames, heap/data segment, references, moved types, shared memory.
You then should be asking "Is it worth using?", then evaluate use cases.. pros/cons.. etc.
For CLI, Rust is likely the easiest given it's macros, but if you struggle with the borrow checker then it won't be. You will be fighting the compiler instead of developing something.
Depending what your CLI program is doing, you might want to evaluate what libraries are available, how they handle I/O, and parallelism.
JavaScript has incredibly easy and fast concurrent I/O thanks to libuv and v8.
Re: Zig self hosted compiler is now capable of building itself
#50Earlier quoted context omitted.
Thanks for the detailed answer! I have more questions, if you'll indulge me: If I understood it correctly, you think smart pointers and reference counting are bad habits. Why? Especially the smart pointers bit. Why does Zig use less memory than other languages? Is it inherent to Zig, or can it be reproduced in other languages?
I think Zig prefers explicit memory management, because allocations may fail and should be handled explicitly, and because automatic deallocations lead to hard-to-predict lifetimes (excess memory usage, and bugs for resource handles that are destructed at hard to predict moments). These are things that a "systems language" programmer should put in the work to do correctly/near-optimally, and not ask the compiler to j…
I don't really feel this is the case in Rust.