Cached at:
11/01/26, 05:40 PM
**TL;DR: In this Zig talk, Sawyer X starts with syntax and focuses on Zig’s core design ideas—making everything visible, avoiding hidden operations, and turning problems into compile-time errors—using configuration parsing and memory allocation as examples.**
# Zig: From Beginner to Slightly Less of a Beginner
## Event Background
This event was hosted by Gabor Szabo, with Sawyer X presenting “Zig: From Beginner to Slightly Less of a Beginner.” It was the Code Maven channel’s first event about Zig. Gabor reminded viewers watching on YouTube to like the video and subscribe to the channel. Links to future events, along with notes and links for this event, would be available below the video.
Sawyer thanked him and outlined a few ground rules for the talk:
- Everyone attending has substantial experience with programming languages. Some have used Zig, some Rust, and some other languages, so he would make many comparisons with other languages.
- The aim was not to mock or ridicule other languages (“except maybe Java”), but to explore an approach to solving engineering problems with a programming language.
- He hoped the audience would avoid the mindset of “I have my language; are you trying to convince me to use yours?” Instead, he wanted them to see it as: “We are all people who use programming to solve problems in the world. How do we deal with these difficult situations we encounter as developers?”
Sawyer also explained upfront that his examples were not necessarily optimal solutions; they were intended to convey an idea—“If you look at this and say, ‘Oh, I could write that better,’ you probably could, and I probably could too, but I wrote it this way to express an idea.”
## About the Speaker
Sawyer X has worked as a developer for more than twenty years, contributed to many open-source and free software projects, and done extensive work on Perl, including being responsible for the language for a time. He has also worked on web frameworks and spoken at many conferences, “usually speaking very loudly and always gesturing with my hands.”
He particularly mentioned his love of programming languages as well as human languages—“but Gonzo is here in this talk, and he is the reason I started learning this.” Even at this event, there were certainly people more capable than he was, so he considered himself a beginner: “I hope that by the end, you will consider yourself a beginner, perhaps slightly less of a beginner than when you joined.”
## Syntax: Dots and Type Inference
Sawyer pointed out that syntax is the first thing someone teaches you when you learn a programming language. He showed a function example containing types (the signed 32-bit integer i32), parameter names A and B (both i32), an i32 return type, semicolons, `return result`, and curly braces.
> “Even though I work in Python a lot these days, part of me still distrusts a language that uses whitespace instead of semicolons. I don’t know why; it seems deeply ingrained.”
Zig has semicolons. That was about it for syntax—“I’m going to cover a lot of Zig, so by the end you’ll understand most of its syntax. But what I really want to talk about is that, when you first learn a programming language, what interests you most is the ideas the language uses to solve problems.”
One recurring detail in Zig is the **dot**: it means “I want you to infer this; I don’t need to spell everything out.” For example, `log` itself has the type `level`, so when you write `.info`, Zig can infer that you mean `level.info`.
## Example: Parsing Server Configuration
Sawyer presented a complete example: a `server` struct containing a `settings` struct—workers, port, and various pieces of information about how it runs. The goal was to obtain a string from a source such as a configuration file and parse it into this struct.
**Requirements and constraints:**
- The log levels are debug, info, and warn.
- `port` is an unsigned 16-bit integer; `workers` is an unsigned 8-bit integer (one byte); `timeout` is a floating-point number because a timeout may be fractional.
- There are defaults, such as port 8080 and log level info, which are overridden when values are received. For example, port, workers, and log may be overridden, while timeout and TLS may not be.
- Data validation is required:
- Someone might supply a string where a number is expected, or a very large number (“perhaps that’s a very high port”).
- Someone might provide an unsupported log level, which needs to be identified as an invalid value.
- Keys that do not exist in server are unsupported. For example, server has no `color`, so that should produce an error.
- Someone might supply only `port` without a port number—the value itself is missing, leaving only the key.
**Code flow:**
1. Import the standard library into a variable so it can be used.
2. Define a `parse_server` function that takes a string (an array of characters/bytes) and returns either a `server` or an error.
3. Create a new server, split the string on spaces using the standard library’s tokenizer, and iterate over all key-value pairs.
4. Split each pair at the equals sign. Failing to find one means there is no equals sign, “which is already good.” When one is found, take the left and right sides to obtain the key and value.
5. Parse and store each value according to its key:
- For `port` and `workers`, use `parseInt`, passing the desired return type, the string value, and the base. Passing 0 also defaults to base 10 and works correctly. `try` means “if you can’t do this, I want you to return an error.” port is U16, while workers gets only one byte (U8), allowing a maximum of 255.
- `timeout` is fractional, so use F32 and `parseFloat`.
- For `log`, use `string to enum` to convert a word such as `info` into the enum value `info`; failure to find it produces its own error.
- For `TLS`, directly compare the words `true`, `yes`, and `no`.
6. If nothing matches, say, “We don’t know what this is.”
Sawyer was candid in his assessment of this code:
> “Looking beyond the syntax itself, you might think what I think, which is that this is ugly. I personally don’t like this code, even though I wrote it.”
What he disliked was having to write out every key, every check, and every storage location. “So we’re going to fix it, but later.”
## Core Idea: Everything Is Visible
This was the real focus of the talk. Sawyer said that if you have used any language other than Zig, when you see `A = B + C`, you may not actually know what it will do—“This is one of the big ‘it depends’ situations we have in programming”:
- Has the plus operator been overloaded? For C, for B, or for both?
- Is C a property that actually has a getter?
- Perl has magic (observable behavior), where touching a variable in some way—writing or reading it—may trigger a callback.
- It also depends on what appears before the equals sign. In Perl, you can even change the value and operation depending on where it is being returned.
- Perl also overloads A and B—`$A` and `$B` are reserved in Perl.
- There may also be an exception, and you do not know where it will go because it is somewhere else.
“It’s hard to know. But in Zig, it will do only one thing: add B and store it in A. That’s it.”
This is one of Zig’s principles. The first thing the language documentation says is: **If something does not look like a function call, it will not call a function.**
Several design choices follow from this:
- **No hidden control flow**: Exceptions being thrown and handled elsewhere do not happen; operator overloading does not exist; property getters and magic callbacks do not exist. This is also why Sawyer likes early exits in functions—“because I don’t have to think about all the other options.”
- **Memory allocation is visible**: When you allocate memory, it is something you can see right in front of you. Either the language provides it, or you need to obtain it globally; it must be there in front of you. Anything that needs to obtain memory from the operating system receives an allocator.
- **No macros**: C and C++ have many options, as does Rust. The idea behind macros is that “you have another language that you use to write the language you want, and then you program in that language—and that’s where the problem is.” In Zig, metaprogramming is Zig itself.
- **defer / errdefer**: These are used when cleaning up memory, but they too are visible, right in front of you, defined in the scope where you need them. “Something is complicated, but you have a clean way to handle it. That is a very consistent behavior in Zig.”
## Zig’s Design Philosophy
Running `zig zen` produces statements that help explain Zig’s design and how Zig code is written. Sawyer summarized it this way: Zig aims to make everything clear and highly visible, right in front of you; it seeks to express your intentions precisely and turn problems into compile-time errors wherever possible.
> “This isn’t a quote from anyone. These are my own words.”
He described programming language design as a pendulum: at one end, you provide a great deal of assistance, giving people what they need in the way you believe is correct, then taking away their control; at the other, you give them complete control but require them to write everything. **Zig tends to seek a middle ground**—it narrows the problem, eliminates many ideas that eventually become part of that ongoing swing, and gives you the right tools to accomplish the task cleanly and elegantly.
Other points worth mentioning: Zig itself is a very small language—“It’s quite small compared to many languages, which I appreciate”; its standard library is large and can do many cool things; “the language itself is very easy to learn; one day is enough.” There is also `zig fmt`.
## Next Example: Memory Allocation
Sawyer’s first full example was **memory allocation**—“something we sometimes overlook, depending on the language, and sometimes suffer because of.”
The scenario: suppose you have a list of users and want to iterate over them to obtain those aged 18 and older. He noted that “there is a very elegant solution that does not require allocating memory,” but suppose we do want to create a new list containing copies of all the adult users—“to do that, we need to obtain some space on the heap.” The talk continued to develop this example from there.
## Summary
The core of this talk was not Zig’s syntax (which is small enough to learn in a day), but the ideas behind it: putting everything in front of you and eliminating hidden control flow, hidden allocation, macros, and overloading, thereby reducing burdens developers never intended to take on.
Source: https://www.youtube.com/watch?v=jWCQXBVIyrY