Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

271–280 of 285 posts

Re: Zig self hosted compiler is now capable of building itself

#271

Earlier quoted context omitted.

It wasn't sarcasm. My "irrelevant" point meant "it's irrelevant for a factor in picking a language", as in "it doesn't significantly contribute to whether a project is possible in the long term". If compile times are longer you just compile less often and write larger portions of code at a time and you generally keep writing code while it compiles.

Works when you've been using a minimal language like C for over a decade and you're an expert. For people learning a new language they constantly need to be recompiling to check their assumptions are correct, that's why it's so important for the masses.

If they're a new developer they're not going to be compiling a massive project over and over I would assume. They'd be writing small toys to learn the language.

Re: Zig self hosted compiler is now capable of building itself

#272
post #251

Earlier quoted context omitted.

In this case, C++?

https://guix.gnu.org/manual/en/html_node/Preparing-to-Use-th... The Guix project likes bootstrappility very much. They basically host a tiny assembly C-compiler (only for a subset of C) which can compile a C compiler written in C for the whole subset that can bootstrap the whole ecosystem.

This link is better: https://savannah.nongnu.org/projects/stage0: bits to asm to C, and then everything else follows.

Re: Zig self hosted compiler is now capable of building itself

#273
post #220

Earlier quoted context omitted.

I haven’t tried Zig yet, but I liked Common Lisp better than Go and Rust for fast CLI apps/scripts. You need to dump an image with all your deps already loaded, and then you can run small scripts with instant compilation very fast. It’s an ergonomic language with good IDE support in emacs. There are some rough edges around (inconsistent API design, the package manager not using HTTPS, …), but tolerable.

Common Lisp doesn't offer features like sum types right? I am under the impression that it is a dynamically typed language like most Lisps, but I could be wrong.

You might peek at Coalton.

https://coalton-lang.github.io/reference/

I don’t think it has sum types, but it offers a rather sophisticated and very functionally oriented type system that compiles back to SBCL. It looks neat, haven’t found time to play yet…

Re: Zig self hosted compiler is now capable of building itself

#274
post #78

Earlier quoted context omitted.

Thanks :) The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons: * It's the second implementation of the language * It did not have to survive as much evolution and language churn * I leveled up as a programmer over the last 7 years * The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of f…

Can you clarify about the union part? Did you meant that zig allowed you replacing what would be untagged union in C++ with tagged union in zig? Or does the zig compiler has some kind of debug sanitizer mode which automatically turns untagged unions into tagged unions with checks?

In debug builds, untagged unions become tagged behind the scenes as you described.

Re: Zig self hosted compiler is now capable of building itself

#275

Earlier quoted context omitted.

What can C and Zig do that Rust can't?

This is kind of a trick question because they are all Turing Complete, but so is Assembly. The best way to interpret your question, then, is not “what is possible” but rather “what is simple to express correctly” and “what is simple to get correct eventually”. Those are questions about how tricky it is to get something to compile in the language and which tools exist to help determine whether a compiled program does…

It wasn't a trick question. I'm not asking it in the same tone as someone would ask 'What can C do that Java can't?'.

I believe that Rust can be as low level as you want. If you have to fight the language to accomplish something, it's because you're probably trying to do something unsafe, and Rust will let you do that if you pay the price.

I was looking for examples of real cases where Zig is a better option than Rust. And while Zig is a lovely language, its main points against Rust are that it lets you do unsafe things more easily, and it's easier to learn.

Re: Zig self hosted compiler is now capable of building itself

#276
post #25

Earlier quoted context omitted.

As someone not familiar with android development, this is somewhat confusing because I always thought Google was pushing dart/flutter for mobile these days? Or is it both at once?

Dart/Flutter is their React Native competitor. It’s in the same space as Xamarin - A secondary language and UI toolkit who’s selling point is rapid development for multiple platforms. Kotlin is to Java (on Android) as Swift is to Objective-C (on Apple) - the successor primary platform language.

I think it is better to compare Flutter with Apache Cordova / Ionic Capacitor, as Flutter actually has a DOM tree behind the scenes, but instead of using a Web View to render the application Flutter renders the app directly to a GPU Accelerated surface using Skia.

Re: Zig self hosted compiler is now capable of building itself

#277
post #256

Earlier quoted context omitted.

I recommend C. Once you get the hang of it, it's as fast as writing Rust code (and you don't have to think about borrow checks).

My biggest gripe with C is not even the manual memory management, since with Valgrind and friends they are not that hard to debug. But how do you solve such a basic issue like having a vector-like data type for different types? Its “macro” system is just a disgusting hack, I could just as well write a sed script instead. And the other option is runtime-overhead or copy-pasting code..

> vector-like data type for different types

When using C, if you want something from a higher-level language, usually you'd just do what that language's runtime does internally. So for a vector of heterogeneous objects, you could do a linked-list of pointers to the data objects. Something like:

    struct VecItm { struct VecItm next; void *data; size_t data_len; char objTypeId; };
Is it more work? Yes. But at this point I would stop and consider if I really need a heterogeneous collection. Do we really need to store a list of objects with arbitrary sizes? What if we have 3 types of objects, in 3 arrays, and we store index into those arrays?

    struct Foo { unsigned byte x; };
    struct Bar { unsigned word x; };
    struct Baz { unsigned long x; };

    struct Foo foos[256];
    struct Bar bars[256];
    struct Baz bazzes[256];

    // objTypeId: 0 = foo, 1 = bar, 2 = baz
    struct VecItm { struct VecItm next; unsigned int idx; char objTypeId; };
Or what if we can do something even better? What if Foo, Bar, and Baz all have a max size that isn't too wildly different? Can we store them all in an array directly?

    // objTypeId: 0 = foo (x contains 8 bits), 1 = bar (x contains 16 bits), 2 = baz (x contains 32 bits)
    struct VecItm { unsigned long x; char objTypeId; };
    struct VecItm vecItms[256];
> Its “macro” system is just a disgusting hack

It's really not that bad. It can result in spaghetti-code where your macros are using other macros and they're spread all over a header file. But if you use them surgically, only when needed, they don't cause much trouble.

> I could just as well write a sed script

The benefit of C macros over sed is if you use some language-aware tooling like an IDE (such as CLion), it will syntax-check and type-check your macros.

Re: Zig self hosted compiler is now capable of building itself

#278
post #135

Earlier quoted context omitted.

It's funny i came to Rust from Go, Python, NodeJS, etc after a combined .. 15 years or so. I've been using Rust full time (work & home) for ~2 years now. Obviously i'm biased, but i quite enjoy it. I find i am more efficient now than before, because it manages to give me the ease of the "easier" languages quite often with a rich set of tooling when i need to go deeper. Personally i feel the concern over the borrow ch…

The problem is that when lifetimes cause you problems, it can force the entire feature development to stop until the problem is fixed. There is no reasonable escape hatch or alternative (clone doesn't always work).

Rc/Arc is usually the escape hatch. I presume you put raw pointers under the "no reasonable" caveat, but if the borrow checker is wrong and you're right, they can be the right tool too. They're not unreasonable if the alternative was to use a different language that couldn't guarantee this safety either.

I know dealing with the borrow checker can feel like a dead-end sometimes, but dealing with it is something that you can learn. Things that it can't handle fall into a handful of common patterns (like self-referential structs). Once you learn what not to do, you can recognize and avoid the issues even before you write the code.

Re: Zig self hosted compiler is now capable of building itself

#279

Earlier quoted context omitted.

And in rust you just put `` in the right scope and you're done. This is perfectly explicit and you know exactly what's going on in your code. Everything is obvious.

You can execute arbitrary code on drop operations by implementing `std::ops::Drop` for a type.

A `.deinit()` function could also run some arbitrary code that does weird and unexpected things. The point is that reasonable people don't abuse functions like that — if they do abuse, don't use their code. Neither Rust nor Zig is a sandbox that could stop actively stupid/malicious code.

Re: Zig self hosted compiler is now capable of building itself

#280
post #256

Earlier quoted context omitted.

My biggest gripe with C is not even the manual memory management, since with Valgrind and friends they are not that hard to debug. But how do you solve such a basic issue like having a vector-like data type for different types? Its “macro” system is just a disgusting hack, I could just as well write a sed script instead. And the other option is runtime-overhead or copy-pasting code..

> vector-like data type for different types When using C, if you want something from a higher-level language, usually you'd just do what that language's runtime does internally. So for a vector of heterogeneous objects, you could do a linked-list of pointers to the data objects. Something like: struct VecItm { struct VecItm next; void *data; size_t data_len; char objTypeId; }; Is it more work? Yes. But at this point…

I don’t want a heterogeneous “array”, I want a generic one. Your first example is the overhead I talked about, most high-level languages don’t do this at all. Pointer chasing is really pricey on this level.

Your second example misses the auto-growing part. Sure, I want an array, but if that becomes too small, I automatically want to realloc the underlying data to a larger array. And I want to use it for Foo, for int and for any sized objects, generally.

C++ can create the proper zero-overhead abstraction over it by generating code for each type I use it for, C to my knowledge can’t do so without copy-pasting code or doing things with runtime overhead, resulting in (often) much slower code.

Post reply on HN