Most active commenters

    ←back to thread

    Zig is hard but worth it

    (ratfactor.com)
    401 points signa11 | 13 comments | | HN request time: 0.273s | source | bottom
    Show context
    latch ◴[] No.36150665[source]
    I've now written a lot of zig code (http.zig, websocket.zig, log.zig, zuckdb.zig, etc.) I think Zig falls into an "easy to learn, average/hard to master" category.

    Some insiders underestimate the effort required for newcomers to build non-trivial things. I think this is because some of that complexity has to do with things like poor documentation, inconsistent stdlib, incompatible releases, slow release cycle, lack of package manager, etc. For an insider living and breathing Zig, not only aren't these huge challenges, they aren't really "Zig" - they are just transient growing pains. For someone getting started though, the current state of Zig is Zig.

    I wish Zig had a polished package manager (there's one in the current development branch, but you don't as much use it as fight it). They could then move some of the less polished code into official experimental packages, helping to set expectations and maybe focus the development efforts.

    replies(7): >>36151206 #>>36152145 #>>36153037 #>>36153777 #>>36159350 #>>36159799 #>>36178599 #
    zoogeny ◴[] No.36151206[source]
    I've lately thought that a package manager is as essential to a new language as a standard library. I would also add a LSP and standard code formatter to that list.

    It is a bit unfortunate because all of the above is a pretty tall order. We're getting to the point that new languages are expected to boil the ocean by the time they reach 1.0

    replies(8): >>36151679 #>>36152038 #>>36152323 #>>36152773 #>>36153966 #>>36154058 #>>36155307 #>>36159420 #
    1. chrsig ◴[] No.36152323[source]
    > I've lately thought that a package manager is as essential to a new language as a standard library. I would also add a LSP and standard code formatter to that list.

    Agreed. Especially on a formatter. The number of code review comments it cuts out is incredibly time and energy saving.

    > It is a bit unfortunate because all of the above is a pretty tall order. We're getting to the point that new languages are expected to boil the ocean by the time they reach 1.0

    In order to get into production? yes. there are minimum requirements that must be met. those are higher now than in the past, because of lessons learned the hard way. those problems have been solved (for some value of solved) in existing ecosystems -- a new language wont change the need for them to be solved.

    it shatters the dream of hacking up something on a weekend and having it turn into a hit success, but it also removes the case of hacking up something in 10 days and suffering the consequences for the next 30 years.

    Until they have what you mentioned, the languages aren't ready for large scale use -- they need to grow into it. They can be useful prior to that -- enthusiasts and early adopters can reap what benefits are provided. That adoption is what fuels the development of things like a standard code formatter.

    edit: fixed omission of a unit of time after '30'

    replies(4): >>36154051 #>>36156226 #>>36158675 #>>36162098 #
    2. clessg ◴[] No.36154051[source]
    > but it also removes the case of hacking up something in 10 days and suffering the consequences for the next 30 years

    Ha, I thought this sounded distressingly familiar!

    "In September 1995, a Netscape programmer named Brandan Eich developed a new scripting language in just 10 days. It was originally named Mocha, but quickly became known as LiveScript and, later, JavaScript."

    replies(1): >>36162085 #
    3. 6keZbCECT2uB ◴[] No.36156226[source]
    Not sure about lsp, but I think if you defined your language in tree sitter, you might be able to define a basic autoformatter generically on tree sitter to accelerate bootstrapping your language.

    You could also use an existing language agnostic package manager like nix, guix, or conda to bootstrap your language package manager.

    Lsp is something I don't know of a way to make that easy without overly constraining the design space.

    4. xormapmap ◴[] No.36158675[source]
    > Agreed. Especially on a formatter. The number of code review comments it cuts out is incredibly time and energy saving.

    Are people realistically reviewing code formatting? As long as people aren't making egregious violations I generally don't care if someone leaves a brace on the same line or writes a one-line if statement. I tend to review the overall design and look for bugs and edge cases that might've been missed. If somebody told me they didn't like the way I formatted the code then they've got their own editor and are welcome to change it if they want to be petty.

    replies(5): >>36158750 #>>36158795 #>>36158810 #>>36159451 #>>36159851 #
    5. xxpor ◴[] No.36158750[source]
    Absolutely. Inconsistency is sloppy, increases cognitive burden while reading code, and can hide bugs.

    Everyone should take the time to setup their editor to format their code consistent with the project style, it doesn't take long at all.

    6. throwawaymaths ◴[] No.36158795[source]
    Nobody is reviewing it. They are rejecting malformatted code in CI step.
    replies(1): >>36160435 #
    7. hyperhopper ◴[] No.36158810[source]
    You're looking at it the wrong way

    People review code. As soon as that happens, formatting is part of the conversation. Either consciously or subconsciously

    8. patmorgan23 ◴[] No.36159451[source]
    The point of the auto formatter is to get those slight differences out of the way so your Brian can focus on parsing and understanding the important parts
    9. brundolf ◴[] No.36159851[source]
    In addition to reviews, I've started to really enjoy format-on-save as a way to save keystrokes. Instead of manually formatting my code (even for myself), I can take the shortest editor path to the AST that I want and then have everything else snap into place
    10. nickcox ◴[] No.36160435{3}[source]
    That's not the workflow your GP is describing.
    11. erhaetherth ◴[] No.36162085[source]
    I think JS was somehow salvaged after all that time. The event loop paradigm is lovely.
    12. erhaetherth ◴[] No.36162098[source]
    Makes me so sad that I can't just code up a parser and have a useable language. I have a lot of ideas, but heck, just syntax highlighting is... I don't know where to begin. And auto-completions. I need a tool that does 90% of that like PegJS or other parser-generators do for the parsing part. Don't see why a parser-generator can't also spit out an LSP. And if it knows what tokens are valid next, it should be able to generate completion suggestions. And if you have an AST, you can probably format the code half decently. And then I imagine it's possible to have a semi-universal package manager, I don't know why we need one per language, really. Aren't they all "put some code in some predefined location, and resolve these dependencies with semver please"? Maybe some extra junk for precompiled deps but still.
    replies(1): >>36175430 #
    13. aldanor ◴[] No.36175430[source]
    Because LSP is not just "give me some semi-decent completions based on parsing tokens in this file". Proper LSP will treat code semantically, in case of e.g. Rust it may complete a method name from a trait method because you have the trait somewhere in scope, which comes from a third-party package which the LSP also parses, where it needs to expand some procedural macros to get to source code, etc etc.

    We've been spoiled by good LSPs, perhaps. But again, it's not just "parse this file please".