7 ms·
Zig by Example
- shaftoe444 4mo agoExamples target Zig 0.14. Been some significant changes since then, not least to printing and formatting (see writergate).
- gren236 4mo agoAlso build system and c interop is outdated
- embedding-shape 4mo agoAh, but are those changes in the training data yet?
- sgt 4mo agoProbably not, but if this is all AI slop then why bother to read it? There's real documentation (and/or just code). Use it
- reactordev 4mo agothere's no question of if here...
- fallingmeat 4mo agolots of people into zig this morning apparently!
- dominotw 4mo agoI am really looking into zig now because founder seems like a cool dude.
- code-blooded 4mo agoI 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://www.openmymind.net/learning_zig/ - https://zig.guide/ https://zig.guide/ - Free project-based online book Introduction to Zig by Pedro Park: https://pedropark99.github.io/zig-book https://pedropark99.github.io/zig-book. - Ziglings, almost working programs you need to fix: https://codeberg.org/ziglings/exercises https://codeberg.org/ziglings/exercises
- iamjackg 4mo ago"More up-to-date" meaning more sources that are also up to date like the OP, or meaning that the OP is not up to date? Silly English language!
- code-blooded 4mo agoZig by Example seems to target Zig 0.14 at the moment. The links I posted should hopefully target version 0.15+
- fallingmeat 4mo agofor those new, start with why: https://ziglang.org/learn/why_zig_rust_d_cpp https://ziglang.org/learn/why_zig_rust_d_cpp
- aselimov3 4mo agoIs this much different than ziglings?
- voidUpdate 4mo agoThis is essentially just a textbook of zig examples. Ziglings is an interactive exercise
- pezgrande 4mo agoI like Zig but stopped learning it when I realized that all project based on it requires a specific version of the compiler to build.
- eclectric 4mo agoI would be interested to learn why that is a problem. As a new Rust learner, I am curious.
- loeg 4mo agoIt might not be the version you have installed, or the same version as another project you want to glue together into a single application.
- zuzululu 4mo agowow. this is a major miss from Zig. on top of the decision to ban AI, I can see that we haven't seen the last of bad decisions from Zig
- hiccuphippo 4mo agoIt is still in active development and before v1. They haven't decided to make it unstable on purpose it's simply not done yet. Anyone using it right now implicitly accepts that they'll have to keep track of the changes in the language and update their code accordingly.
- noelwelsh 4mo agoVery 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.
- miroljub 4mo agoLooking 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.
- voidUpdate 4mo agoIf you worked through this and learnt to use zig, your token usage would be even lower!
- short_sells_poo 4mo agoDon't be ridiculous. Learning? That's for the dinosaurs. Just throw an llm at the problem!
- all2 4mo agoBoth is good. I do both, and to get reasonable output from an LLM I _have_ to do both.
- miroljub 4mo agoWhat's wrong with learning by reviewing the LLM generated code and asking questions interactively? Works for other languages.
- anonfunction 4mo agoOne 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/ https://tigerbeetle.com/ 2. https://tigerstyle.dev/ https://tigerstyle.dev/ 3. https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TIGER_STYLE.md https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TI...
- all2 4mo agoBest 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.
- baalimago 4mo agoI'm missing the concurrency model.
- deleted 4mo ago[deleted]
- Zambyte 4mo agoFor what it's worth, the concurrency model is very similar to the one in Go. Zig has std.Io.Queue instead of channels, std.Io.async and std.Io.concurrent instead of the go keyword, and switch over std.Io.Select instead of the select keyword. There are lots of resources on concurrency in Go, and the learning semantics would carry nicely over to Zig.
- jdw64 4mo agoIs 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.
- tempaccount420 4mo agoIMO, there isn't much space left to fill that Rust couldn't already fill.
- code-blooded 4mo agoSimplicity is one thing Zig excels at (at least from my early observations).
- Zambyte 4mo agoYup. Rust tries to make it hard to do systems programming poorly. Zig tries to make it easy to do systems programming well. Rust pushes you into certain (good) practices. Zig makes it exceptionally easy to understand what's happening, making good practices the obvious choice.
- dnautics 4mo agoHow crazy is it to have a language where combining two foundation traits is such a huge footgun that the linter has to warn you (but somehow you can't ban it within the language)
- repelsteeltje 4mo ago
- stephc_int13 4mo agoEncapsulating 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...
- brodo 4mo agoIn Zig, function arguments are not wrapped in `.{}`. `.{}` is the syntax for creating a struct or a tuple. This is used as a pattern for allowing optional arguments (options struct) and variadic functions (tuple). Explicitly discarding return values is a thing many modern programming languages force you to do.
- stephc_int13 4mo agoI know, and I don't see unused return values as an error, it should be a warning at best. And the compiler should be just a bit smarter to avoid the .{} thing when it is not strictly necessary.
- dnautics 4mo ago> And the compiler should be just a bit smarter to avoid the .{} thing when it is not strictly necessary. What's your plan for this? Rebuilding the C varargs mess from first principles?
- dnautics 4mo ago> Encapsulating arguments inside .{} seems superfluous and noisy. You don't do this? This is only for varargs or optionals. .{<stuff>} is just a shorthand for Type{<stuff>} (struct constructor) plus, "hey compiler, you figure out the type". So if anything it's LESS noisy than the alternative, and more forward-compatible if you change a type name for example.
- hiccuphippo 4mo ago
- yrds96 4mo agoThis is outdated and AI generated. If you want a good source of zig learning material interactive and by examples please check out ziglings: https://codeberg.org/ziglings https://codeberg.org/ziglings It's writen and tested by humans, which is essential for learning purposes. It's listed in the official zig website, by the way. This project is always up to date to the latest zig release.
- systems 4mo agowell, it also made by the same guy behind the boring go book which probably means that boring go is also most likely AI generated nowadays before reading or buying any book, we need to extensively investigate the author, the author name is now more important than ever, i think whenever a book is shared, the author need to me highlighted
- embedding-shape 4mo ago> nowadays before reading or buying any book, we need to extensively investigate the author I mean not really. You read a paragraph or two and notice the quality of the text, start getting suspicious and continue two or three paragraphs more, notice some very basic inconsistencies/incoherence, realize it's AI-written and ctrl+w the tab (or put back the book in the shelf) and move on with your life. If there is no samples of the book, I'd hesitate to even consider buying it, just so you can actually sample the text. Very easy in bookstores luckily, so not a huge problem in the end.
- Jblx2 4mo agoYou can just read a paragraph or two of each email, and then decide whether or not to delete them. We don't additional tools to combat spam.
- embedding-shape 4mo agoKind of feels like a slightly different thing, I don't spend days/weeks reading through one email.
- b33j0r 4mo agoDo not use this, I recommend ziglings if anything besides what Loris would say: you have to read code. The builtins don’t even compile in these examples. This is 2 years out of date at least.
- tapirl 4mo agoHaving quick viewed all the chapters, the examples are too simplistic to fully demonstrate Zig's syntax and semantics.
- porteghal 4mo agojust read it fast and easy! for a starter like me? amazing!
- atique29 4mo agoMy gut feelings had me check the Zig version. "Examples target Zig 0.14." Ah there we go
- mustaphah 4mo agoYou would probably be better off reading learnxinyminutes.com/zig/
- elxr 4mo agoAgreed. Love that site.
- Thanemate 4mo ago3 commits? Really? Why don't I just ask Claude or chatGPT instead?
- synergy20 4mo agodoes zig still matter in the AI era? i was learning zig on and off and now have no motivation to learn it anymore.