One might say that writing a “Hello, World!” example is Zig programming, but that is not my point. Given Zig’s unique features and internals, what are the various attributes that a complete Zig program must consist of? Furthermore, how must the program be structured to excel at delivering what Zig promises?
A program is an executable and its associated files.
A zig program would be a program written mostly or entirely in zig, I generally would not include libraries in that metric.
Programming is not a game you win by using all the features, it is a tool to accomplish something. That something could be as small as curiosity/fun or as large as creating a better alternative to a major piece of software.
You would not measure a table based on how many ways a particular kind of saw was used in its construction.
Zig doesn’t necessarily have a “gimmick”, so to say, but if you had to classify it in one sentence, you could probably say a Zig program is a program, written in a low level, with fine control over allocations.
I counter that with, a good zig program is one written with the necessary systems in mind.
Which practically always encompasses memory and allocations, but does not necessitate low level or fine control as they may not be relevant or even optimal for the domain.
This is less about the language and more about the philosophy that lead to its creation and the wonderful communities we have.
Sorry to be snarky, but: A Zig program is one that is written in Zig. Period.
The last thing this community needs is defining what program is “ziggy” or “un-ziggy” to qualify. It’s one of the things I think is wrong with some of the other languages’ communities, so please, don’t bring that attitude here. Let’s just enjoy programming, share that joy, share what may objectively be improved about each of ours code. Let’s not allow cargo cult to consume us.
It is important to clarify what a Zig program actually is. My intention with this question is to find out exactly what to learn—such as proper memory management, build.zig, and so on. Syntax, to a large extent, isn’t as important to learn since LLMs can handle that, but knowing what a Zig program is helps one tailor and focus their learning.
Honestly, I don’t think that’s a very good approach, as each Zig program may be very different depending on what it is. A one-shot CLI tool will have a completely different architecture than a long-running server daemon, which will have a completely different architecture than a video game.
Instead of focusing on what to learn to make “a Zig program”, I would advise to instead go and learn what you need to write your particular program that you have in mind. In fact, focus more on language-agnostic concepts (algorithms, memory management, graphics, etc.), and only then try to bring those concepts over to Zig. At that point, if you have some concrete questions about how to do something in Zig, I can wholeheartedly recommend bringing those to this forum. There are some very helpful folks from all walks of life here who will certainly be able to help you make your program the best Zig program it can be.
I don’t know, I think we may not need arbitrary rules on what is “Ziggy enough”. It might be valuable to think about what features/syntaxes/patterns to focus on for different types of work and education, sure.
But I think @spiffyk’s main point here is to steer clear of anything that might sound like we’re claiming that it is the One True Ziggish Way, which would be a) above my pay grade and b) unnecessarily clique-ish.
I’m not even saying you are trying to do that but maybe “What is a Zig program” covers a lot of ground. What do you want to cover?
Zig is one of the the languages where the main benefit is that it stays out of your way. So I don’t think there is a “ziggy” way of programming.
I think if you asked a thousand experts “What is a C program?” then you would get two thousand answers, most of which would be (like here) “No.”.
On the other hand, if you said “I want to write a book introducing {specific-language-here} programming to new people, what should it cover?” then you’d start to converge on some answers.
Lol 100% agree with this. As long as it’s written in Zig it’s a Zig program. It doesn’t have to be idiomatic and it could be the worst spaghetti code with as much memory leaks you’ve ever seen type of app, and it still would be a Zig program.
good advice. thanks.
My question is more about getting to understand Zig. You may agree that a program such as a ‘Hello, World!’, which is a valid Zig program, teaches the developer nothing about the language. While on the other hand, another program can be written in such a way that teaches the developer more about the Zig language.
So the question was, what’s a project that can cover the major features of Zig?
If you cover everything, it’s likely to be an artificial exercise and not a realistic program. Learning a programming language isn’t a one and done thing. That’s why Ziglings is a series of small programs. Each focuses on a particular aspect.
A programming language is just a tool. The real question is, what do you want to create?
I don’t know that I’d agree that Hello World teaches a developer nothing.
Once you understand everything about the code that “zig init” generates, you have a stake in the ground that you can focus a discussion around things like:
- allocators
- arguments
- stdout and writers and buffering
- try and error reporting
- build.zig
- build.zig.zon
- testing
And you already have “zig build” support for:
- building for Debug/ReleaseSafe/ReleaseFast/ReleaseSmall
- building for other operating systems and architectures
Sure, it’s only the simplest possible intro to each of those but it’s not nothing either.
I’ve been a little abstract here because it’s kind of an abstract topic (interesting!, but abstract). Sorry.
In an effort to be more concrete, here’s some things I’m wondering:
Are you looking for some folks further along to give some pointers on what you personally should study? And if so, maybe you don’t have anything in mind but just want to talk, or maybe there’s a project in mind that you’re not sure how to describe?
Are you looking to collaborate on creating some documentation to give to others? And if so, what do we know about those ‘others’?
I will 100% agree that a zig program is just any program written in zig.
If you are talking about what the language pushes you towards I’d say that honestly, after using it full-time for about 9 months it felt like the language had a strong opinion that it forced on me on very few things.
- Zig pushes you more towards using unsigned over signed integers
- If you use ranges (start..end) zig pushes you more towards using start being inclusive and end being exclusive.
- If you want to process some assets before your code runs, the language pushes you more towards doing that with build.zig instead of comptime (If you just read I think it’s in principle possible to do with comptime, but I had issues with the compiler crashing with unkown errors). With @cimport moving to the build system, it seems there’s a growing list of things that zig pushes you towards doing in build.zig.
I’d say these were the only times I felt like I was fightting the language, other than that zig let’s you do your own thing.
As far as programming religion:
I think most people using zig will tell you to favor writing Data Oriented Code and that OOP is not a good idea, and I am certainly one of them. Also Arena allocators are awesome.