News for hackers. Stuff that matters.
Re:What can TypeScript learn from Zig? What can Zig learn fr... by kkjkj on Thursday July 18, 2024 @09:10AM (#40995245)
Interesting comparison! TypeScript could definitely benefit from Zig's simplicity and performance-centric design. Zig's focus on explicitness and avoiding hidden control flow is something that could make TypeScript's type system even more robust. On the flip side, Zig could learn a lot from TypeScript's widespread adoption and ecosystem. TypeScript's gradual typing and extensive tooling make it very developer-friendly, which is an area where Zig could improve. What do you all think? Are there any specific features from one that you'd like to see in the other?
Re:What can TypeScript learn from Zig? What can Zig learn fr... by flohofwoe on Thursday July 18, 2024 @09:28AM (#40995394)
One feature from TS (or rather JS) that I start missing in Zig is destructuring and spreading.

For instance it would be nice if instead of this:

    const bla = @import("bla.zig");
    const a = bla.a;
    const b = bla.b;
    const c = bla.c;
...I could write this:

    const { a, b, c } = @import("bla.zig");
...which would be normal destructuring (since the result of a Zig import is a struct).

And in reverse it would be nice if there would be some equivalent to the spread operator:

    const a = Bla{ .x = 1, .y = 2, .z = 3 };
    const b = Bla{ ...a, .z = 4 };
...this would be the same as `b = Bla{ .x = a.x, .y = a.y, .z = 4 }`

...same for working with arrays and slices (there is a form of destructuring specifically for tuples, but IMHO that's a too narrow use case for a much too useful feature).

I'm not actually a fan of porting Typescript's advanced type system features over to Zig, a lot of those features would require the use of tagged unions (aka sum types) for pretty much everything, which IMHO just doesn't feel right for a low level systems programming language (since the tagged union always carries around the 'weight' of it's biggest type).

...also thinking about it, some Typescript features for building new types from existing types can probably be emulated with Zig's comptime features.

Re:What can TypeScript learn from Zig? What can Zig learn fr... by danvk on Thursday July 18, 2024 @10:40AM (#40996006)
Destructuring assignment was definitely something I missed in Zig (it's even called out in the post). Here's the relevant issue/comment, which makes me think this won't happen in Zig: https://github.com/ziglang/zig/issues/3897#issuecomment-7389...
Re:What can TypeScript learn from Zig? What can Zig learn fr... by Reki on Thursday July 18, 2024 @10:44AM (#40996044)
Its in zig 0.12
Re:What can TypeScript learn from Zig? What can Zig learn fr... by danvk on Thursday July 18, 2024 @12:21PM (#40997165)
For tuples, not for named fields.