17 votes

Zig: The small language (2022)

10 comments

  1. [2]
    tjf
    Link
    My only significant use of Zig so far is as a nicer way to interface with C libraries, specifically the forthcoming SDL3. And for that it's kind of perfect. The build system is so much better than...

    My only significant use of Zig so far is as a nicer way to interface with C libraries, specifically the forthcoming SDL3. And for that it's kind of perfect. The build system is so much better than writing janky makefiles and I appreciate the compiler's sensible defaults. I also like that the language itself is documented on a single big web page. Zig feels a lot more approachable to me than some of the other C replacement languages out there.

    10 votes
    1. pete_the_paper_boat
      Link Parent
      Also, lesser known, but certainly documented. For browsing the standard library you can run zig std (iirc) and it'll host it locally as a webpage. It uses WebAssembly n things for search I think.

      Also, lesser known, but certainly documented. For browsing the standard library you can run zig std (iirc) and it'll host it locally as a webpage.

      It uses WebAssembly n things for search I think.

      3 votes
  2. [2]
    akselmo
    Link
    Whenever i tried Zig, its syntax is so full of stuff that I cant remember how to work with it. It feels way more complicated than it should be. On top of that, it's far from stable so code you...

    Whenever i tried Zig, its syntax is so full of stuff that I cant remember how to work with it. It feels way more complicated than it should be.

    On top of that, it's far from stable so code you write today may just break tomorrow.

    Still, it's on my re-try list whenever it stabilizes more. I am currently using Odin and having tons of fun with it.

    4 votes
    1. pete_the_paper_boat
      (edited )
      Link Parent
      I think you mean the compilation, cause the standard library moves around a bit every version. I think a major downside is that the only reliable way to learn how to use things is to jump into the...

      On top of that, it's far from stable so code you write today may just break tomorrow.

      I think you mean the compilation, cause the standard library moves around a bit every version.

      I think a major downside is that the only reliable way to learn how to use things is to jump into the standard library source code. Which can be intimidating at first if the syntax feels too verbose.

      3 votes
  3. [5]
    drannex
    (edited )
    Link
    const std = @import("std"); const print = std.io.getStdOut().writer(); pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer gpa.deinit(); const heaps = gpa.allocator();...
    const std = @import("std");
    const print =  std.io.getStdOut().writer();
    
    pub fn main() !void {
       var gpa = std.heap.GeneralPurposeAllocator(.{}){};  
             defer gpa.deinit();
    
        const heaps = gpa.allocator();
    
        const reply = 
    

    \\ Sure, yeah, everyone on tech forums post about Zig and heaps about how great it is (or how much "better" a certain dark-souls level crustacean compiler boss might compare), but this is really one of the first articles I read that had me interested in the language and convinced me to seriously start using it in all my projects.
    \\
    \\ C became one of my favorite languages over the last decade, especially during the great pandemic, but I think Zig might take that crown for the time being. Zig just feels like what C17/C23 would have ended up becoming in another universe, it's great.
    \\
    \\ Side note: If Odin had more support, I would love to throw everything I have at it. Such a better (fresh) language design, after spending some more time in Zig, I might start writing similar utilities I see in Zig into Odin if I can find the time to add to that repository of information and packages for them.

        ;
    
       print(reply);
    }
    
    3 votes
    1. [3]
      pete_the_paper_boat
      (edited )
      Link Parent
      You've got an undefined symbo there, general_purpose_allocator. Also, gpa.deinit() returns a value that explicitly must be discarded. defer _ = gpa.deinit(); ...and the print statement seems to...

      You've got an undefined symbo there, general_purpose_allocator.

      Also, gpa.deinit() returns a value that explicitly must be discarded.

      defer _ = gpa.deinit();

      ...and the print statement seems to simple to be Zig, I'm sure that writer is meant to be var and doesn't return a function.

      Also I think we can all agree the literal string syntax you used here should be in more languages.

      2 votes
      1. drannex
        (edited )
        Link Parent
        Considering I wrote this up on my phone, we should be incredibly lucky that this is even passable. lol. But that undefined is driving me crazy, going to edit that and leave the rest... errors and all.

        Considering I wrote this up on my phone, we should be incredibly lucky that this is even passable. lol.

        But that undefined is driving me crazy, going to edit that and leave the rest... errors and all.

        4 votes
      2. shu
        Link Parent
        There's also an _ = heaps; missing, since otherwise it's an unused local constant. 🙂

        There's also an _ = heaps; missing, since otherwise it's an unused local constant. 🙂

    2. ogre
      Link Parent
      What sort of projects have you been using Zig (or Odin) for?

      What sort of projects have you been using Zig (or Odin) for?

  4. pete_the_paper_boat
    Link
    It now has both, albeit they axed async as a language feature to do it.. It might return, maybe, at some point..

    I look forward to Zig becoming more stable, hopefully having a self-hosted compiler and a package manager.

    It now has both, albeit they axed async as a language feature to do it..

    It might return, maybe, at some point..

    3 votes