11 ms·
Hey man, first of all thanks a lot for you efforts. This and ziglearn.org are just great as a starting point. If I may here are three additional pieces of info
by overflyer 6y ago
Hey man, first of all thanks a lot for you efforts. This and ziglearn.org are just great as a starting point.
If I may here are three additional pieces of information that if added to your documentation will clarify some more things for the beginner/reader:
1) Arrays and Slices section
Arrays in Zig are values. They store the pointer and the length, but an array is a value so the raw pointer can never be accesses unless....
You coerce the array to a slice. A slice reveals a pointer to you.
2) Add tagged unions (I do not understand what they are but they exist, maybe some fellow reader here could help me)
3) If, for, while and switch can ALSO BE EXPRESSIONS!
Now to the part that does not address you directly but everyone.
These tutorials are great, but they are the mere starting point. I admire Zig and its design, I admire Andrew and that awesome community, I love Zig Showtime and everything. But there are two problems I have with Zig that annoy me and that is only because I REALLY want to learn it and ditch C already:
* I am trying to figure out how to do system's programming. Like use all the system calls and their system library wrapper equivalent's that I am so used to in C. After an hour of research on the net I could not even figure out how to read in and go through the contents of a file (fread, fstat, fgets, fopen). That stuff needs to go into the official documentation or at least to ziglearn.org
* The same way the Zig compiler is awesome the underlying build file you often wanna write is just horribly documented. I don't understand half of it and it changes a lot. Andrew should really politely ask people on the internet to take down old repos and blog entries.
Please document the build system and build file writing better.
- friend-monoid 6y agoI remember doing some basic IO using clib. There’s is a flag, like —link-clib or something. Then you can include header files as you would in C. I created a basic example a while ago doing some basic IO, epoll, timers, and linking in a C obj file, just to try out how to do embedded in zig. It’s really good. Another upside with Zig coming from the embedded world is Zigs idea of doing async/await - since you define the building blocks yourself, it’s really easy to create an async/await-implementation e.g. on top of epoll, but for those times when your hacking on bare metal, you can just write an implementation which fits that particular hardware. It’s really, really good.
- overflyer 6y agoOh damn I should have realised importing C files would be a solution and I will definitely try that. However, I would still much prefer a native Zig way.
- deleted 6y ago[deleted]
- AnIdiotOnTheNet 6y ago> 2) Add tagged unions (I do not understand what they are but they exist, maybe some fellow reader here could help me) It is probably a matter of terminology. For some reason different languages see fit to give the same thing different names. A union is a type that can be one of several different things. In C unions, there is no built-in way to tell which of those things any given union instance is at any given moment, which can lead to code assuming it is one thing when it is actually another. Tagged unions carry an enum with that that tells you which thing they are right now. Zig will not let you work with a tagged union's value unless you switch on the enum (tag) so you know what you're working with. > * The same way the Zig compiler is awesome the underlying build file you often wanna write is just horribly documented. I don't understand half of it and it changes a lot. Andrew should really politely ask people on the internet to take down old repos and blog entries. Please document the build system and build file writing better. Agree wholeheartedly. I've never even bothered to use zig build in years of working with zig because of it. Granted, I make it a rule to rethink what I'm doing if I actually need a complicated set of build steps, but sill.
- ljm 6y agoDocumentation is definitely not the language's strong point just yet, but that's understandable when it's still on a 0.x release and it's a massive work in progress with ambitious goals. The reference is useful at a high level, the autogenerated stdlib stuff is highly hit and miss and I suppose will be ripe for community contribution when the method of generating it is nailed down. The language itself is fantastic once you get a decent grasp of it, which you'll probably achieve by reading the stdlib source to get a feel for what you need to do. I've been using it to build stuff on my Pi Zero. Still hit a few snags with cross compilation and C interop, but it's been a pleasure to write. I'm definitely keeping an eye on it as a good alternative to getting into Rust.
- jorangreef 6y agoI'm also looking to use Zig for a Pi. Any tips? If you publish a blog post please give me a ping!
- ljm 6y agoI'll collect my thoughts on it as I'm still not completely there, but I'll have something when I've got it working.
- ljm 6y agoI've put it all here if it's any use for ya :) https://www.kamelasa.dev/programming/gettin-ziggy-with-it-pi-zero/ https://www.kamelasa.dev/programming/gettin-ziggy-with-it-pi...
- jorangreef 6y agoHey, thanks! That's a brilliant post, awesome tone and a huge help. I really appreciate it and have passed it on to everyone at work.
- sobeston 6y agoMaintainer of ziglearn.org here. I have just now added details on using stat and directory creation + walking here: https://ziglearn.org/chapter-2/#filesystem https://ziglearn.org/chapter-2/#filesystem And details on reading the next line here: https://ziglearn.org/chapter-2/#readers-and-writers https://ziglearn.org/chapter-2/#readers-and-writers fread/fstat/fgets/fopen is now all covered. The build system is something I need to cover much more thoroughly, but is something that will take a long time.
- overflyer 6y agoDUDE WHAT. I hope not just because of my post. Anyways that is so amazing thank you so so so much. I post something, you come along and just basically say "wish granted" :D.... You and your page are just great!!!!!! thx!!!
- kristoff_it 6y agoHey overflyer, thank you for the kind words, and the criticism too. What you're asking is absolutely reasonable and I agree that these are things that should exist. The blocker (for the things that I control / can contribute to) is mostly effort and resulting value. I considered the idea of working on a book that would do a proper introduction. It's something that would be useful, without a doubt, but the problem is that it would take a lot of effort and time (given my current skillset) and it would take away from other possibilities that in my estimate would be more cost-effective for the project. So the TLDR is that we're genuinely thinking constantly of what's the next best move to make and, given the situation the project is right now, we think other things have to take priority. Of course we could be making a wrong estimate, so we're open to discussing it, but we have to follow the path of least resistance, which means making temporary compromises. My bet is that if we play our cards well there will be enough skilled communicators interested in writing Zig programming manuals, we just have to get there first :) I also want one day to write a book on comptime, hopefully it won't take too long!
- overflyer 6y agoOmg is that you Loris? Never ever have I written a post and got that amount of nice feedback. First the maintainer of ziglearn.org and now you. This is the thing I love so much and if you guys combine this absolutely amazing attitude with some professional marketing I just see a bright, bright future for the Zig language. I tried all the so called C replacements, and especially Rust. The Zig language is the only approach where one does not need an IQ of a 130 to learn it. Just please you guys do everything to not vanish into a absolute niche like D did, because D was and in my opinion still is such a great candidate/language, they just should have done better marketing. I would be looking forward for your book and would be the very first one to buy it!!! Also, can I donate to ziglearn, Zig Showtime and/or the Zig Foundation? In my opinion Linus should think about letting Zig into the kernel and not Rust :D. Maybe one day you guys will also achieve that.
- kristoff_it 6y agoYo it's a-me, Loris! Thank you again, we try :) If you want to support the ZSF, here you can find all the information you need: https://ziglang.org/zsf/ https://ziglang.org/zsf/ I'm the one answering mails to donations@ziglang.org, btw. For ziglearn and Zig Showtime, I guess you should check our respective GitHub profiles.