Remix.run Logo
Zig by Example(github.com)
119 points by dariubs 2 hours ago | 35 comments
stephc_int13 3 minutes ago | parent | next [-]

Encapsulating arguments inside .{} seems superfluous and noisy.

I'm sure this can be rationalized in some way, to either simplify parsing or solve some rare ambiguity, but I just don't see it.

I know this is a minor thing and can be considered as nitpicky, and I expect some friction with syntax when learning a new language, but I just can't stand things I see as gratuitous. Same with the forced use of _ = foo(.{}); to avoid compiling errors...

jdw64 22 minutes ago | parent | prev | next [-]

Is Zig just a trend, or will it become a solidly established language? After all, learning something is an investment of time. With Zig, it doesn't seem to have the same kind of industry pressure as Rust. There's talk in open source circles about AI-related issues, and on Hacker News people say good things about Zig. The allocator concept looks great. But there's also a possibility that it won't become mainstream, like the D language. I personally like D and think its compiler is beautiful, but being linguistically good is different from being industrially adopted. So should I learn Zig, or wait a bit longer?

For now, I have a basic grasp of C#, a little Python, a little C++, and a little TypeScript. I also know Java to some extent, but honestly, what I mostly build is CRUD app assembly. To go deeper, I think I need to dig into a systems language. But I'm not sure whether to invest in Zig or Rust.

the__alchemist a minute ago | parent | next [-]

I'm suspicious that the user base is people who like to program using pointers in business logic. So, the subset of current C programmers who are willing to switch.

With this in mind: Does anyone here program in Zig, or know someone who does who is not a current C (or C++) programmer?

pseidemann 15 minutes ago | parent | prev | next [-]

If you want to learn systems programming, I can recommend learning C. If you want to learn a programming language which allows systems programming, I guess Rust is not a bad choice. But it might be less helpful if the systems basics are unknown.

raincole 9 minutes ago | parent | prev | next [-]

What's the difference between a trend and a solid language? I bet many (I mean like millions) people still think Rust is a trend.

> To go deeper, I think I need to dig into a systems language

Most of such code is still written in C.

tempaccount420 16 minutes ago | parent | prev | next [-]

IMO, there isn't much space left to fill that Rust couldn't already fill.

code-blooded 9 minutes ago | parent [-]

Simplicity is one thing Zig excels at (at least from my early observations).

groan 14 minutes ago | parent | prev | next [-]

Unless you’re actively promoting one of the languages for financial gain, you have nothing to lose by delaying commitment to one, both, or either. If any of them have lasting value, they will be as easy to pick up in the future as they are now. Nobody cares about the old Java or .NET versions where both suffered from limited implementations of generics and other things, and nobody is a better programmer for having used them back then compared to picking them up today.

jdw64 10 minutes ago | parent [-]

Learning a language is ultimately for the purpose of building something, so doing both is a bit difficult. Personally, I find Zig easier and more approachable than Rust, so I've been reading about it, but I'm worried about what I can actually do with it

CyberDildonics 12 minutes ago | parent | prev [-]

It's unsafe and intentionally crashes on windows newlines and tabs. If C adopts defer, I don't think there will be enough of a differentiation to overcome the cynical user hostility.

code-blooded 2 hours ago | parent | prev | next [-]

I just looked this up yesterday so sharing some more up-to-date resources for those interested in Zig:

- Learning Zig by Karl Seguin: https://www.openmymind.net/learning_zig/

- https://zig.guide/

- Free project-based online book Introduction to Zig by Pedro Park: https://pedropark99.github.io/zig-book.

- Ziglings, almost working programs you need to fix: https://codeberg.org/ziglings/exercises

shaftoe444 2 hours ago | parent | prev | next [-]

  Examples target Zig 0.14.
Been some significant changes since then, not least to printing and formatting (see writergate).
embedding-shape 28 minutes ago | parent | next [-]

Ah, but are those changes in the training data yet?

sgt 18 minutes ago | parent [-]

Probably not, but if this is all AI slop then why bother to read it? There's real documentation (and/or just code). Use it

gren236 2 hours ago | parent | prev [-]

Also build system and c interop is outdated

pezgrande an hour ago | parent | prev | next [-]

I like Zig but stopped learning it when I realized that all project based on it requires a specific version of the compiler to build.

nvme0n1p1 44 minutes ago | parent | next [-]

The situation will improve once they release a stable 1.0 version.

Until then, use mise, nix, docker, or something similar. (You should be doing this anyway for projects in all languages if you care about them building on anyone's machine other than your own.)

eclectric an hour ago | parent | prev [-]

I would be interested to learn why that is a problem. As a new Rust learner, I am curious.

tialaramex 10 minutes ago | parent | next [-]

Historically, say, 15 years ago before 1.0, Rust too was always shifting about and so you'd find that the software you wrote last month now doesn't even compile and the advice has changed.

Today most people write entirely stable† Rust, and as somebody else mentioned Rust uses Editions to allow it to make any remaining language improvements, but if you were writing mostly unstable Rust you would see a reduced version of the same churn. Last month you could foozle.boozle() and that gets you a Wibble, but then you upgraded and now foozle doesn't have a boozle method, and apparently Wibbles no longer exist at all, everybody says you need to learn about Wumps instead now because those are apparently better or something?

† If you don't use a "nightly" build of Rust or a special opt-in "nightly mode" your Rust compiler only recognises the stable language.

loeg an hour ago | parent | prev | next [-]

It might not be the version you have installed, or the same version as another project you want to glue together into a single application.

afavour 29 minutes ago | parent | prev [-]

Rust has editions, which can be mixed and matched between different dependencies. AFAIK Zig does not have this.

fallingmeat 2 hours ago | parent | prev | next [-]

for those new, start with why: https://ziglang.org/learn/why_zig_rust_d_cpp

noelwelsh an hour ago | parent | prev | next [-]

Very brief. I'm not sure what this adds over reading the language documentation (which itself is not great). As it's entirely organized by language features it doesn't really talk about any larger scale design decisions, which is where I think language proficiency is really found.

baalimago an hour ago | parent | prev | next [-]

I'm missing the concurrency model.

aselimov3 an hour ago | parent | prev | next [-]

Is this much different than ziglings?

voidUpdate 30 minutes ago | parent [-]

This is essentially just a textbook of zig examples. Ziglings is an interactive exercise

fallingmeat 2 hours ago | parent | prev | next [-]

lots of people into zig this morning apparently!

dominotw an hour ago | parent [-]

I am really looking into zig now because founder seems like a cool dude.

miroljub an hour ago | parent | prev [-]

Looking for a resource (MCP, CLI, Skill, ...) that would improve Zig support in LLMs.

Currently, doing something with Zig as a target language would spend many more tokens and produce subpar results.

all2 3 minutes ago | parent | next [-]

Best bet is tight integration with a language server and the zig docs as MD locally. You may also pull in the zig source code as canonical reference for best practices.

From there you can derive a set of tools and references that you can build skills on.

Any LLM can scratch together an MCP server, its basically FastAPI + functionality. Your goal, then, is to identify the subset of tools and data required to get 'good' output.

If you want to test your MCP server implementation, grab the source of several popular zig projects, rewind their git history, and have your LLM of choice attempt to address PRs for issues on those repos. Compare LLM solutions with the repo solutions, grade on token spend, LOC produced, variance from Zig best practices, and so on.

anonfunction 18 minutes ago | parent | prev | next [-]

One of the preeminent Zig software projects, Tigerbeetle[1], has a great website[2] and markdown file[3] for what they call TigerStyle.

It's honestly a great read as a human but also I packaged it as a skill and saw coding agent improvement, especially around memory usage.

1. https://tigerbeetle.com/

2. https://tigerstyle.dev/

3. https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TI...

voidUpdate 37 minutes ago | parent | prev [-]

If you worked through this and learnt to use zig, your token usage would be even lower!

short_sells_poo 34 minutes ago | parent | next [-]

Don't be ridiculous. Learning? That's for the dinosaurs. Just throw an llm at the problem!

all2 2 minutes ago | parent [-]

Both is good. I do both, and to get reasonable output from an LLM I _have_ to do both.

miroljub 20 minutes ago | parent | prev [-]

What's wrong with learning by reviewing the LLM generated code and asking questions interactively? Works for other languages.