Earlier quoted context omitted.
Psuedo-Rust code here, showing off both styles. Parameterized by an allocator: struct Foo { // ... } impl Foo { fn new() -> Foo { // do something to make a new foo, calling functions via A } } contrast with "an allocator is passed in explicitly to every method which actually needs to allocate." struct Foo { // ... } impl Foo { fn new (a: A) -> Foo { // do something to make a new foo, calling functions via A } } (EDIT…
Thanks for the example. I wasn't aware this is something that was planned for Rust, seems like a pretty large breaking change. Interesting!
Zig and Rust
31–40 of 247 posts
Re: Zig and Rust
#32Earlier quoted context omitted.
Thanks for the example. I wasn't aware this is something that was planned for Rust, seems like a pretty large breaking change. Interesting!
Nothing is breaking! The change isn't a move to a zig-like style, but instead, that in today's Rust, you have struct Foo { // ... } and not struct Foo { // ... } This isn't breaking because there is a default type provided for A. The handwave is over "Today's Rust", as this machinery has already landed, in a sense, it's just not really possible to use with the standard library because the allocator API isn't fully st…
[0] https://internals.rust-lang.org/t/why-bring-your-own-allocat...
Re: Zig and Rust
#33> Collections are not parametrized by an allocator, like in C++ or (future) Rust. What does he mean by this?
Psuedo-Rust code here, showing off both styles. Parameterized by an allocator: struct Foo { // ... } impl Foo { fn new() -> Foo { // do something to make a new foo, calling functions via A } } contrast with "an allocator is passed in explicitly to every method which actually needs to allocate." struct Foo { // ... } impl Foo { fn new (a: A) -> Foo { // do something to make a new foo, calling functions via A } } (EDIT…
Author mostly notes that this is more flexible. I can see it being possible in each case to have the system be parametric in the allocator, though it'll be a lot more annoying in Rust give the need to pipe the types around.
Something between that noisiness and the global default does bias Rust toward being uncreative with its choice of allocator.
I wonder, too: in this example, the author notes that because their init function takes an allocator and their event loop doesn't, therefore the event loop does no allocation. But, as long as a global allocator could be accessed from somewhere besides your entrypoint, you could still be calling it. Does Zig offer a capabilities model like that?
All in all, I think this difference is more subtle than Matklad is making it out to be, but I in no way doubt that he's correct. Especially in today's Rust.
Edit: I did some research on Zig and also noticed HashMapUnmanaged which might be more what Matklad was referencing. In pseudo-Rust, it has
impl HashMapUnmanaged {
fn put(&mut self, key: K, value: V, allocator: A);
}
This justifies the statement "Rather, an allocator is passed in explicitly to every method which actually needs to allocate." and makes it much more clear where Zig has gone here.Re: Zig and Rust
#34This title is almost perfectly designed to do well on HN, but it's definitely worth reading in it's entirety. Some highlights for me: - The author sees Rust and Zig in different niches. When Rust was created it didn't need to specialise because there were no languages like Rust. It was free to be a general purpose language targeting multiple domains. But that's not the case for Zig. He sees Zig shining at writing sys…
Where can I read more about this? What ended up happening?
Re: Zig and Rust
#351) Zig is memory-unsafe and thread-unsafe whereas Rust isn't.
2) Zig is easier to learn whereas Rust isn't.
3) Zig isn't stable yet whereas Rust is.
ChatGPT can help with Rust:
https://news.ycombinator.com/item?id=33872369
However ChatGPT can't help with Zig since Zig hasn't stabilized yet. Features like for-loops (introduced in 2022) aren't familiar to ChatGPT since ChatGPT's cut-off date is 2021.
Re: Zig and Rust
#36I tried zig after reading so many HN articles and I am not impressed. You have to remember to free after each allocation. The language is supposed to be simple, yet there exist try, catch, defer, errdefer. Rust enums make defining errors so simple with arbitrary payload. Using data structures in rust is much nicer. I think unless you have some precise needs about memory allocation, and want to control exactly where w…
> I think unless you have some precise needs about memory allocation, and want to control exactly where when and how memory is allocated, it is hard to argue in favour of Zig. I do have a hard time to think of use cases other than embedded microcontroller work where that matters nowadays. That said, I suspect that while they could have written TigerBeetle in Rust (no_std does not assume the existence of an allocator)…
People keep saying things like this and software keeps getting more bloated and shittier. It is difficult to believe there isn't a correlation.
Re: Zig and Rust
#37Earlier quoted context omitted.
Not the parent, but Zig being much easier to use unsafely is not a good thing IMO. Rust tries to pave a path for all types of developers to eventually learn how to write performant code safely in a way that integrates cleanly. This is a much more practical need for the programming community at this time. I have to agree with the parent - I was interested in looking at Zig eventually, but after reading this I am not.…
Agree with everything you've said. > I don't need a language This, but the bigger issue is that I don't think I can be trusted with such a sharp tool. I'm just aware of my own limitations, and I think I'd better stick to safe languages.
Re: Zig and Rust
#38Re: Zig and Rust
#39I already know Rust and shipped nontrivial stuff, but I need something simpler that average developers can pickup quickly to produce performant+parallel code and be able to crosscompile+ship a single binary.
(The last point already ruled out Crystal which has a poor crosscompilation story as well as insanely long compile times for nontrivial stuff = bad DX)
Re: Zig and Rust
#40I tried zig after reading so many HN articles and I am not impressed. You have to remember to free after each allocation. The language is supposed to be simple, yet there exist try, catch, defer, errdefer. Rust enums make defining errors so simple with arbitrary payload. Using data structures in rust is much nicer. I think unless you have some precise needs about memory allocation, and want to control exactly where w…
Zig is verbose and low-level and, to like it, you have to appreciate simplicity and what it means to have control over tiny details. If you don't like either thing, then Zig will not bring anything particularly interesting to the table for you.