News for hackers. Stuff that matters.
Re:Was Rust Worth It? by freilanzer on Thursday October 26, 2023 @05:41AM (#38023567)
Why is there no need to improve Zig code but there is for Rust code? You'd need the same abstractions in Zig as well, no?
Re:Was Rust Worth It? by cztomsik on Thursday October 26, 2023 @06:05AM (#38023686)
No, usually you don't. Rust has closures, iterators, generics, different traits for operator overloading, smart pointers, etc.

Zig doesn't have any of that. It's very interesting combination of low-level, predictable code, with meta-programming, where you get some of that abstraction back.

i.e. Zig does not have generics, but your function can return type, so generic list is just a function which returns a newly created struct.

Re:Was Rust Worth It? by mst on Thursday October 26, 2023 @10:09AM (#38025796)
Could you expand on the generics point, please? That sounds interesting but I can't quite get my head around it.
Re:Was Rust Worth It? by lr1970 on Thursday October 26, 2023 @10:30AM (#38026100)
Zig has `comptime` where you effectively generate Zig code at compile time by writing Zig code, no special generics syntax/semantics needed. It is very nice and powerful concept that covers lots of ground that in Rust would belong to the land of procedural macros.
Re:Was Rust Worth It? by cztomsik on Friday October 27, 2023 @10:33AM (#38038965)
Functions in Zig can be called both in runtime and in compile-time. You can force some expression to be called during comptime using a keyword, and sometimes the comptime is implied (like when you define top-level const)

If a function is called in comptime, it can also return types. So for example:

    // this is a function which accepts a type
    // if you accept type, you also have to restrict the arg to be comptime
    // if the arg is comptime it still does not mean that the function cannot be called in runtime,
    // but in this case, it returns type, so it is comptime-only function
    // there are also cases where this is not true, like std.mem.eql(u8, a, b) which accepts type,
    // but can be called in runtime because it does not return type
    fn Wrapper(comptime T: type) type {
        return struct { value: T };
    }

    const F32Wrapper = Wrapper(f32);

    // @TypeOf(x.value) == f32
    var x: F32Wrapper = .{ value: 1.0 }
Re:Was Rust Worth It? by epage on Thursday October 26, 2023 @09:19AM (#38025135)
Can't speak for why Zig doesn't have a problem but Rust is cursed by its success: it lowers the barrier for improvement enough to entice you to always improve it.
Re:Was Rust Worth It? by cztomsik on Friday October 27, 2023 @10:26AM (#38038887)
No. Rust forces you to spend endless hours doing mental gymnastics which shouldn't be needed in the first place (linked data-structures, owned arenas, or even just boxed slices are impossible in safe rust).

And you just keep refactoring/improving/desperately trying different ideas, because it never feels right.

It's ok if you don't agree but pls don't try to make my responses look like I like Rust, I don't and I'd happily get those years back if it was possible.