Failing to Learn Zig via Advent of Code

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • zig

    General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

    I've seen some comments here about how recommending to read the source code is unhelpful. I vehemently disagree because of practicality first (if something is not documented elsewhere, then that's the best you can do) and second because reading the source code should not be considered something primitive that developers used to do before discovering fire.

    We all should read more and write less.

    That said, Andrew is going to help me start this week the work on a new doc autogeneration system based on a different design that the current (incomplete) one. I'll do most of the work while streaming on Twitch so if anybody has opinions, complaints or questions, you know where to find me: https://twitch.tv/kristoff_it

    Going back to the post, there were also some impressions that we all fully agree with (and are working on improving), an good example being

    > Bit-shifting is a monumental pain in the ass.

    Yes, it indeed is. See: https://github.com/ziglang/zig/issues/7605

    Ok, so, here's my advice to forrestthewoods if you're ever going to try Zig again:

    [1] Interact more with the community if you want to be pointed quickly in the right direction. You mentioned the discord server so you already interacted with people. Leverage them more: ask questions in #zig-help and don't be afraid to ask why things are a certain way. You'll probably be way less annoyed by, say, ArrayList requiring you to access its `items` field to iterate, if somebody explains to you that in Zig there are no "magic methods" that the compiler picks up to do iteration etc. Or maybe you won't be less annoyed, but at least you will know if something is intentional or if it's just something that we haven't gotten around fixing yet.

    [2] Try to learn Zig doing something else other than Advent of Code. AoC doesn't really let Zig show it's potential because it doesn't ask you to do good sotware engineering. You're just supposed to write a script that gets you to the correct answer. Try instead doing a small project where you have to validate input, produce useful error messages to the user, clean up resources properly (sockets, memory, ...), etc. You will find that Zig will be much better in this second case. I'm saying this based on first hand experience btw, I've streamed the first 16 days of AoC from this year, you can find the recordings in this playlist: https://www.youtube.com/watch?v=wo580tbLSR8&list=PL5AY2Vv6Es...

    I stopped after day 16 because I felt it the exercises didn't really help me showcase any big strength of Zig, so I started working on other stuff instead.

  • The-Quick-Snippet-Reference

    Let's build the quickest snippet reference for every programming language, free to use and modify.

    I recently started learning Rust by adding snippets to The Quick Snippet Reference [0]. Without any previous knowledge of the language I knew there had to exist a data type for dynamic arrays. After several Stack Overflow searches I found it: Vec. It was very interesting to compare to Python's Array. Getting to understand the drain() method was a refreshing experience. I'm still hesitating about the best way to handle errors (Rust has no exceptions, just panic!), but that will probably become clearer when working with threads.

    [0]: https://github.com/snippetfinder/The-Quick-Snippet-Reference

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • ziglyph

    Unicode text processing for the Zig programming language.

    > My big problem with Zig is that Andrew Kelley is promising a lot of features, but doesn't really deliver much.

    Have you, like, seen the release notes for 0.9.0?

    https://ziglang.org/download/0.9.0/release-notes.html

    > Zig still can't proper handle UTF-8 strings [1] in 2022

    There's plenty of discussion on the subject in basically every HN thread about Zig: the stdlib has some utf8 and wtf validation code, ziglyph implements the full unicode spec.

    https://github.com/jecolon/ziglyph

    You might not like how it's done, but its factually incorrect to state that Zig can't handle unicode.

    > In a `recent` interview[2], he claims that Zig is faster than C and Rust, but he refers to extremely short benchmarking that has almost no value in the real world.

    From my reddit reply to this same topic:

    This podcast interview might not be the best showcase of the practical implications of Zig's take on safety and performance. If you want something with more meat, I highly recommend Andrew's recent talk from Handmade Seattle, where he shows the work being done on the Zig self-hosted compiler.

    https://media.handmade-seattle.com/practical-data-oriented-d...

    Lots of bit fiddling that can't be fully proven safe statically, but then you get a compiler capable of compiling Zig code stupidly fast, and that's even without factoring in incremental compilation with in-place binary patching, with which we're aiming for sub-millisecond rebuilds of arbitrarily large projects.

    > The ecosystem for zig is insignificant now and a stable release would help the language.

    I hope you don't mind if we don't take this advice, given the overall tone of your post.

  • reason

    Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems

    OCaml is pretty close already to what you're describing. The OCaml ecosystem fully embraces imperative programming. And if the syntax of OCaml is problematic, then perhaps ReasonML (https://reasonml.github.io/) is what you're looking for: a curly-braces syntax for OCaml.

  • zig-string

    A String Library made for Zig

    Why does something as basic as uppercasing a string or decoding latin1 require a third-party library? I would expect that to be part of stdlib in any language. Also, why does that third-party library come with its own string implementation? What if my dependency X uses zigstr but dependency Y prefers zig-string <https://github.com/JakubSzark/zig-string>? Basically all languages designed in the past 30 years have at least basic and correct-for-BMP Unicode support built-in/as part of stdlib. Why doesn’t Zig?

  • cmu-infix

    Updated infix.cl of the CMU AI repository, originally written by Mark Kantrowitz

    The Lisp version can also be more readable with a macro (like https://github.com/quil-lang/cmu-infix): #I(a(1.0-t) + bt). Or something else that would let you write GP's preferred syntax. One of the things that makes Lisp Lisp is that if the parens are over-cumbersome, you have the tools to take them away. See also CL:LOOP.

  • ffmalloc

    That's not a C flaw, you can use an allocator that prevents use-after-free.

    https://github.com/bwickman97/ffmalloc

    The point of C and Zig is that they are low level and you can do whatever, like not use an allocator, or write an allocator.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

  • tigerbeetle

    Discontinued A distributed financial accounting database designed for mission critical safety and performance. [Moved to: https://github.com/tigerbeetledb/tigerbeetle] (by coilhq)

    > Checked arithmetic is a much bigger performance hit than most people expect.

    You're right about the branching cost. I believe there's a better way to solve that though then simply disabling checked arithmetic everywhere.

    I am the tech lead for TigerBeetle [1], a new distributed database that can process a million financial transactions per second.

    We differentiate between the control plane (where we want crystal clear control flow and literally thousands of assertions, see NASA's "The Power of 10: Rules for Developing Safety-Critical Code") and the data plane (where the loops are hot).

    There are few places where we wouldn't want checked arithmetic in TigerBeetle enabled by default. But where the branch mispredict cost relative to the data is too high, Zig enables us to mark the block scope as ReleaseFast to disable checked arithmetic.

    [1] https://www.tigerbeetle.com

  • swift

    The Swift Programming Language

    So here is a sample,

    Chapel, HPC language mostly sponsored by Intel and HPC

    https://chapel-lang.org/

    D programming language,

    https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

    Ada/SPARK,

    https://docs.adacore.com/spark2014-docs/html/ug/en/source/la...

    Swift,

    https://github.com/apple/swift/blob/main/docs/OwnershipManif...

    ParaSail

    http://www.parasail-lang.org/

    Project Verona from Microsoft Research

    https://www.microsoft.com/en-us/research/project/project-ver...

    Project Snowflake from Microsoft Research

    https://www.microsoft.com/en-us/research/publication/project...

    And finally your favourite C++

    "Implementing the C++ Core Guidelines’ Lifetime Safety Profile in Clang"

    https://llvm.org/devmtg/2019-04/slides/TechTalk-Horvath-Impl...

    Also the "Clang Static Analyzer - A Tryst with Smart Pointers" talk at 2021 LLVM Developers Meeting.

    For the Visual C++ part of the story

    https://devblogs.microsoft.com/cppblog/lifetime-profile-upda...

    And GCC as well, although they are late to the party

    https://gcc.gnu.org/wiki/DavidMalcolm/StaticAnalyzer

    Finally a couple of CppCon 2021 talks that touch on the subject in various ways,

    Type-and-resource safety in modern C++

    Code Analysis++

    Static Analysis and Program Safety in C++: Making it Real

    Finding Bugs Using Path-Sensitive Static Analysis

    So here is a sample,

    Chapel, HPC language mostly sponsored by Intel and HPC

    https://chapel-lang.org/

    D programming language,

    https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

    Ada/SPARK,

    https://docs.adacore.com/spark2014-docs/html/ug/en/source/la...

    Swift,

    https://github.com/apple/swift/blob/main/docs/OwnershipManif...

    ParaSail

    http://www.parasail-lang.org/

    Project Verona from Microsoft Research

    https://www.microsoft.com/en-us/research/project/project-ver...

    Project Snowflake from Microsoft Research

    https://www.microsoft.com/en-us/research/publication/project...

    And finally your favourite C++

    "Implementing the C++ Core Guidelines’ Lifetime Safety Profile in Clang"

    https://llvm.org/devmtg/2019-04/slides/TechTalk-Horvath-Impl...

    Also the "Clang Static Analyzer - A Tryst with Smart Pointers" talk at 2021 LLVM Developers Meeting.

    For the Visual C++ part of the story

    https://devblogs.microsoft.com/cppblog/lifetime-profile-upda...

    And GCC as well, although they are late to the party

    https://gcc.gnu.org/wiki/DavidMalcolm/StaticAnalyzer

    Finally a couple of CppCon 2021 talks that touch on the subject in various ways,

    Type-and-resource safety in modern C++

    Code Analysis++

    Static Analysis and Program Safety in C++: Making it Real

    Finding Bugs Using Path-Sensitive Static Analysis

  • chapel

    a Productive Parallel Programming Language

    So here is a sample,

    Chapel, HPC language mostly sponsored by Intel and HPC

    https://chapel-lang.org/

    D programming language,

    https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

    Ada/SPARK,

    https://docs.adacore.com/spark2014-docs/html/ug/en/source/la...

    Swift,

    https://github.com/apple/swift/blob/main/docs/OwnershipManif...

    ParaSail

    http://www.parasail-lang.org/

    Project Verona from Microsoft Research

    https://www.microsoft.com/en-us/research/project/project-ver...

    Project Snowflake from Microsoft Research

    https://www.microsoft.com/en-us/research/publication/project...

    And finally your favourite C++

    "Implementing the C++ Core Guidelines’ Lifetime Safety Profile in Clang"

    https://llvm.org/devmtg/2019-04/slides/TechTalk-Horvath-Impl...

    Also the "Clang Static Analyzer - A Tryst with Smart Pointers" talk at 2021 LLVM Developers Meeting.

    For the Visual C++ part of the story

    https://devblogs.microsoft.com/cppblog/lifetime-profile-upda...

    And GCC as well, although they are late to the party

    https://gcc.gnu.org/wiki/DavidMalcolm/StaticAnalyzer

    Finally a couple of CppCon 2021 talks that touch on the subject in various ways,

    Type-and-resource safety in modern C++

    Code Analysis++

    Static Analysis and Program Safety in C++: Making it Real

    Finding Bugs Using Path-Sensitive Static Analysis

    So here is a sample,

    Chapel, HPC language mostly sponsored by Intel and HPC

    https://chapel-lang.org/

    D programming language,

    https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

    Ada/SPARK,

    https://docs.adacore.com/spark2014-docs/html/ug/en/source/la...

    Swift,

    https://github.com/apple/swift/blob/main/docs/OwnershipManif...

    ParaSail

    http://www.parasail-lang.org/

    Project Verona from Microsoft Research

    https://www.microsoft.com/en-us/research/project/project-ver...

    Project Snowflake from Microsoft Research

    https://www.microsoft.com/en-us/research/publication/project...

    And finally your favourite C++

    "Implementing the C++ Core Guidelines’ Lifetime Safety Profile in Clang"

    https://llvm.org/devmtg/2019-04/slides/TechTalk-Horvath-Impl...

    Also the "Clang Static Analyzer - A Tryst with Smart Pointers" talk at 2021 LLVM Developers Meeting.

    For the Visual C++ part of the story

    https://devblogs.microsoft.com/cppblog/lifetime-profile-upda...

    And GCC as well, although they are late to the party

    https://gcc.gnu.org/wiki/DavidMalcolm/StaticAnalyzer

    Finally a couple of CppCon 2021 talks that touch on the subject in various ways,

    Type-and-resource safety in modern C++

    Code Analysis++

    Static Analysis and Program Safety in C++: Making it Real

    Finding Bugs Using Path-Sensitive Static Analysis

  • zls

    A Zig language server supporting Zig developers with features like autocomplete and goto definition

    > Building is slow. It takes about ~3 seconds minimum which is frustratingly slow when I'm fighting basic syntax errors. I wish there was a fast zig check.

    > Lack of zig-analyzer makes learning hard.

    > zig fmt src/main.zig is nice. Wish it automatically ran on all files.

    I also did (well, "am doing", can only work a bit each day and am plugging through day 7 right now) AdventOfCode in Zig this year.

    These points here didn't resonate with me at all. I wonder if the author knew about or tried ZLS[0]. I had it on and integrated with my VSCode and it would check a lot of things as I went and format on save. I think I followed something like this[1] to set it up.

    [0] https://github.com/zigtools/zls

  • v-mode

    🌻 An Emacs major mode for the V programming language.

    I did improve my Go skills solving all problems in Go, learning many things the hard way, but at end my solutions were way longer and so much less ergonomic than the NumPy & Python-based I saw by the top 100 guys! I mean, come on, Go doesn't even have built-in min(), max(), abs(), and other basics (for ints)! Some of the top developers had their solutions done in a shorter time that I needed to read the overly convoluted and confusing problems. I just didn't appreciate the infantile, and wasteful pseudo-comical style of problem definitions! I've attended any programming contest back in Bulgaria and I can't recall anything that required me to read everything carefully 2-3 times before I get what needs to be done (oh, well, I wasn't 48 back then). I also got fascinated by GitHub Copilot, which actually autocompleted many of those missing basics and surprisingly "guessed" what I was trying to accomplished and offer meaningful productivity boost. I also looked into Zig, but, honestly, I didn't like many of the syntax choices made. Instead, I installed V [0], and will actually try to use it as it fits me better.

    [0]: https://vlang.io/

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts