News for hackers. Stuff that matters.
Re:Zig in 30 Minutes by andi999 on Sunday January 03, 2021 @01:03AM (#25619889)
I am always interested in zig, but these mini tutorials don't give you anything beyond what simple C does (apart from the exceptions). The full docs do not have enough examples (last time I checked). I would really like something like K&R for zig.
Re:Zig in 30 Minutes by sobeston on Sunday January 03, 2021 @10:44AM (#25622375)
Hi, I am currently writing ziglearn.org which aims to show a lot of detailed examples.
Re:Zig in 30 Minutes by StreamBright on Sunday January 03, 2021 @10:53AM (#25622429)
Please include the following if you have a chance:

- parsing command line arguments

- logging (loglevels, files, stdout/stderr, etc.)

- talking to a restful service via HTTP

Thanks in advance!

Re:Zig in 30 Minutes by sobeston on Sunday January 03, 2021 @02:25PM (#25624330)
Getting command line arguments is covered here:

https://ziglearn.org/chapter-2/#iterators

I don't think that going further into parsing is in scope. std.log is something that definitely needs to be covered. HTTP, I'm not sure about as it requires a lot of extra machinery outside of the standard library and these things aren't mature yet.

Re:Zig in 30 Minutes by DixieDev on Sunday January 03, 2021 @08:40AM (#25621693)
It's hard to rationalise putting together a fully fledged guidebook when the lang is still quite unstable, with things changing very regularly. Once it hits 1.0, or possibly a short time beforehand, more people will be willing to both learn the language and/or create in-depth write-ups.
Re:Zig in 30 Minutes by andi999 on Monday January 04, 2021 @10:55AM (#25632910)
Does this mean zig is not ready for production?
Re:Zig in 30 Minutes by DixieDev on Tuesday January 05, 2021 @08:41AM (#25645363)
I would recommend avoiding any language in production environments until they at least hit version 1.0, unless you're able and willing to contribute by dealing with issues you encounter as you go, and fixing backward compatibility breakages as the language is updated.
Re:Zig in 30 Minutes by flohofwoe on Sunday January 03, 2021 @05:08AM (#25620837)
IMHO the official documentation:

https://ziglang.org/documentation/master/

And the (fairly new, and still a bit thin) std library documentation

https://ziglang.org/documentation/master/std/#std

...gives a good enough rundown to start writing real-world code if you're coming from another C-like programming language.

Re:Zig in 30 Minutes by dilap on Sunday January 03, 2021 @08:23AM (#25621622)
I've also found the std library code to be very clean and readable. Try taking a look at e.g. <zig>/lib/std/array_list.zig
Re:Zig in 30 Minutes by andi999 on Sunday January 03, 2021 @05:20AM (#25620888)
In my opinion it doesn't. I Shows all the features/keywords but it doesn't teach you how to use it properly. I presume you didn't study K&R?
Re:Zig in 30 Minutes by jorangreef on Sunday January 03, 2021 @05:35AM (#25620955)
To be fair, K&R (as awesome as it is) also doesn't cover things like epoll or io_uring? And then again, K&R's definitely not a half hour read.

Zig's std lib documentation will keep getting better. In the meantime, the std lib code itself is so well written, it's worth a read, even coming from another language, and even if you have no intention to learn Zig. I found it easy to read and was impressed by the code structure and quality of the design.

Of course, that's not to suggest that code is documentation, but I've learned alot about improving my programming in general, just by reading Zig's std lib.

Re:Zig in 30 Minutes by andi999 on Sunday January 03, 2021 @05:55AM (#25621017)
I do not want epoll and io_urig covered in the teaching material. I mean you don't learn a language by reading a dictionary is all I am trying to say.
Re:Zig in 30 Minutes by daurnimator on Sunday January 03, 2021 @07:12AM (#25621332)
> you don't learn a language by reading a dictionary

I love this quote, adding it to my quote list; is it from something?

Re:Zig in 30 Minutes by andi999 on Sunday January 03, 2021 @08:09AM (#25621559)
Glad you like it. I think I just made it up when typing the reply, since the documentation reminded me of a dictionary. But I wouldn't be surprised if this has been said before.
Re:Zig in 30 Minutes by banachtarski on Sunday January 03, 2021 @10:00AM (#25622115)
epoll and io_uring (the latter of which did not exist when K&R was written) have nothing to do with C though
Re:Zig in 30 Minutes by pjmlp on Sunday January 03, 2021 @11:10AM (#25622557)
K&R C also doesn't teach how to write code that is actually correct in modern C compilers, nor does it teach C best practices on how to at least try to write safe code in C.
Re:Zig in 30 Minutes by andi999 on Sunday January 03, 2021 @11:18AM (#25622635)
Agree. But it did all this at the time it was published. That's just what I would need for zig. It is OK that this doesn't exist, it just mean one person less picking up the language.
Re:Zig in 30 Minutes by jorangreef on Sunday January 03, 2021 @01:01PM (#25623506)
Yes, that's the point I want to make.

Zig the language, and Zig the std lib have two different sets of documentation. The former is really, really good, and I wouldn't say lacking at all, considering Zig is still pre-1.0. Take a look here: https://ziglang.org/documentation/master/

It's the Zig std lib auto-generated documentation (i.e. I/O things like epoll and io_uring and much more) that is incomplete, and to which most of the "documentation is lacking" and "read the std lib source" comments relate.

It's only if you want to know how to use Zig for things like I/O, then you'll need to read the std lib source (and the growing number of blog posts and talks etc), in the same way that K&R is also not always helpful as a guide for these things (and others) today in C.

But the Zig language itself is pretty easy to grok from the excellent language documentation and examples already linked to.

Re:Zig in 30 Minutes by andi999 on Monday January 04, 2021 @12:47AM (#25628246)
For me it is not easy to grok. Then let me ask you: I need a (large) 3 dimensional array where the size of each dimension is unknown at compile time. What is the zig way to do this, how do I access the elements.

Bonus question: I have a function doing a transformation on this array, what is the way to duplicate this array

Re:Zig in 30 Minutes by flohofwoe on Sunday January 03, 2021 @05:31AM (#25620940)
I've read K&R Second Edition, but only after I already learned C through other means. From that PoV, K&R is an interesting look into the design rationale of C against its historic background, but since it is stuck at C89 I wouldn't recommend it today to learn the language TBH :)