A Review of the Zig Programming Language (Using Advent of Code 2021)

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.

  • > Everything in Zig is const x = blah;, so why are functions not const bar = function() {};?

    Accepted proposal: https://github.com/ziglang/zig/issues/1717

    > The builtin compiler macros (that start with @) are a bit confusing. Some of them have a leading uppercase, others a lowercase, and I never did work out any pattern to them.

    In idiomatic zig, anything that returns a type is uppercased as though it were itself a type. Therefore the vast majority of builtins will start with a lowercase letter. I think it is only `@Type`, `@TypeOf`, `@This`, and `@Frame` that don't.

  • zigstr

    Zigstr is a UTF-8 string type for Zig programs.

  • 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.

    InfluxDB logo
  • adventofcode-2021

  • I also did AoC 2021 in Zig: https://github.com/avorobey/adventofcode-2021

    One thing the OP didn't mention that I really liked was runtime checks on array/slice access and integer under/overflow. Because dealing with heap allocation is a bit of a hassle, I was incentivized to use static buffers a lot. I quickly figured out that I didn't have to worry about their sizes much, because if they're overrun by the unexpectedly large input or other behavior in my algorithms, I get a nice runtime error with the right line indicated, rather than corrupt memory or a crash. Same thing about choosing which integer type to use: it's not a problem if I made the wrong choice, I'll get a nice error message and fix easily. This made for a lot of peace of mind during coding. Obviously in a real production system I'd be more careful and use dynamic sizes appropriately, but for one-off programs like these it was excellent.

    Overall, I really enjoyed using Zig while starting out at AoC problem 1 with zero knowledge of the language. To my mind, it's "C with as much convenience as could be wrung out of it w/o betraying the low-level core behavior". That is, no code execution hidden behind constructors or overloads, no garbage collection, straight imperative code, but with so much done right (type system, generics, errors, optionals, slices) that it feels much more pleasant and uncomparably safer than C.

    (you can still get a segmentation fault, and I did a few times - by erroneously holding on to pointers inside a container while it resized. Still, uncomparably safer)

  • ziglings

    Learn the Zig programming language by fixing tiny broken programs.

  • It's unfortunately the only comprehensive reference I know of besides the official docs.

    There is "Ziglings", but those are a collection of small exercises with answers rather than a full guide.

    https://github.com/ratfactor/ziglings

    If you know of better resources than these two, please do share (not being passive aggressive here).

  • Nim

    Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).

  • To me Zig doesn't seems like a zombie.

    - It is actively developed, has frequent releases and it is steered toward a stable 1.0

    - The crowd funding model proves that some users want that language.

    - It doesn't try to revolutionize coding, it tries to be a better C, hence the wowlessness

    Nim¹ and Crystal² have probably more chances of eventually becoming dead languages but I hope they don't as they are both fun languages.

    1- https://nim-lang.org/ : Nim is a statically type checked compiled Pythonesque language with a type system residing somewhere between Pascal and Ada.

  • crystal

    The Crystal Programming Language

  • TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • > but it's not true of generics in most languages

    not sure how true that is.

    TypeScript: https://github.com/microsoft/TypeScript/issues/14833

  • 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.

    WorkOS logo
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