I didnt know about ziglings. I just jumped straight in with the source code of the std lib as my hemp guide. I will have a look, although after 4 months I’m pretty comfortable with zig. But I did C for 33 years and like I said in my zig videos: “zig is like seeing in old friend (c in this case) and realize they had plastic surgery making them look great”.
Thanks for this tutorial. You've inspired me to take a serious look at Zig. I chose to solve this problem by splitting the input on "
" instead of " " the first time. Then, I have two iterators: an outer loop that loops over the elf groups obtained by the previous split and an inner while loop that loops over splitting the current group with " ". The outer loop keeps a count of the elfs and the inner loop adds up the amounts of the current elf. If the amount is larger than any of the previous one, update an outer variable with the larger amount and update another outer variable with the current elf's count. After both loops are done, print out the two outer variables. Subscribed! Thank you.
Hi, I'm new to a programming language with manual memory menagement. I was wondering doesn't arena allocator supposed to free all memory it's allocated so you don't need to manually free each object? Here 30:23 the author defer deallocation of the read_buf which was allocated using arena allocator.
Ziglings look like a fine place to start learning, but... having to learn based out dev version for someone that has no clue out to work with zig is not very good approach. I have the latest version of Zig and I can run ziglings because it requires some dev version. Anything that should be point out for teaching should always come from stable code.
Zig will be a moving target until 1.0. I played through Ziglings a year ago and then helped Dave update it. It's invariably out of date again. Maybe you can help update it too. You'll learn a lot, even if, especially if, the language changes (subtly). Because you'll have an educated opinion as to why.
I haven't read through all of the comments to see if this has been mentioned or not... When you "install" a new version wouldn't it be better to keep the folders name as is and then just create a symlink call zig to the version you want? This way you can always reverence which versions you have downloaded as well as which version is in use.
couldn't you create a var "elfmaxamount" initialized to zero, then when doing the loop and hitting the line of length zero, compare elfamount to elfmaxamount, and overwrite elfmaxamount if elfamount is bigger, then zero out elfamount? This avoids ever using the array.
Julia language: max_elf = current_sum = 0 for l in eachline("input.txt") if isempty(l) max_elf = max(max_elf, current_sum) current_sum = 0 else current_sum += parse(Int, l) end end println(max_elf) This gives the correct output in 10 lines of code vs. 43 lines of Zig. For a scientist, these verbose languages are out of the discussion. I think C is even better than this when it comes to time and effort required from the programmer. I'm not against the development of new programming languages, that's how new ideas are to be explored anyway, but I'm wondering why language features like memory safety are at the forefront of language design and the users (us) are a second thought? Maybe Rust is enough for those who have plenty of time to waste fighting the compiler? I hope more developers focus on the user first and try new ideas.
I absolutely don't understand the allocator code that you wrote. C's malloc makes more sense to me then what Zig does. The way malloc can be used to allocate memory is much more simpler. What is this ArenaAllocator that you create with page_allocator? It looks bizarre and I don't see an explanation here. Zig's syntax looks like an unholy marriage between Java and C.
I did a bit of googling and I wrote this program without all this memory allocation for the file handling. I used bufferedReader and stuff and it probably allocates memory in the background, but at lease I understand what the code does.
Spoke too soon. I did end up creating an allocator for the ArrayList. Not the same allocator shown in the video though. I used this one -- std.heap.GeneralPurposeAllocator(.{}){};
Copilot and ChatGPT got othering? You don’t say 😂 For my define video I created a Game Genie NES code generator and I figured let’s ask Chat Jippity to see if it can optimize my code a bit. It took my code where I have an array that translates hex to GG characters and turned it in to an if the else tree 😂and that didn’t even compile on Zig. I kept telling it that an operator it chose did not existing zig. But it kept hammering on 😂I then figured let’s just optimize my bit shifting algorithm the bit wide operations in zig are identical to C so it must be able to…. Yeah totally screw that up as well 😂I don’t want to use either of that crap. It’s so bad!
hard to get enthusiastic about a language when the getting started guide is wrong and doesn't work and the example code won't run when you follow the instructions to build it. and there's virtually no documentation about it.
zig has potential... but god damn, its ugly and verbose.. []u8 as string? da fuck? passing anonymous struct to print even when u don't pass any argument? list goes on.. odin should get more love.. better language
If you think the potential it has is something contingent on resolving this ugliness or verbosity though, then you are mistaken. Because these are the result of the fulfillment of the languages design goals. There is a WHOLE lot of discussion about these decisions in the issue tracker though if you don't understand the motivation behind them, and given how much discussion when into many of these decisions, they aren't likely to change substantially. I don't think odin is a better language. I like odin though, and I think it is probably the sanest newer alternative to zig for people who feel this way about it.
He is a great communicator and did extremely well! It’s a privilege to have access to high quality content like the one we have here. It might not be your style but being negative and not providing constructive criticism is just a sign of lack of respect to yourself as a learner. Learn to learn, start with the basics and be polite.
I didnt know about ziglings. I just jumped straight in with the source code of the std lib as my hemp guide. I will have a look, although after 4 months I’m pretty comfortable with zig. But I did C for 33 years and like I said in my zig videos: “zig is like seeing in old friend (c in this case) and realize they had plastic surgery making them look great”.
Thanks for this tutorial. You've inspired me to take a serious look at Zig. I chose to solve this problem by splitting the input on "
" instead of "
" the first time. Then, I have two iterators: an outer loop that loops over the elf groups obtained by the previous split and an inner while loop that loops over splitting the current group with "
". The outer loop keeps a count of the elfs and the inner loop adds up the amounts of the current elf. If the amount is larger than any of the previous one, update an outer variable with the larger amount and update another outer variable with the current elf's count. After both loops are done, print out the two outer variables.
Subscribed! Thank you.
Just found out your channel, and that's an awesome tutorial, keep going Matt! Got a new follower and fan!
I also have zig videos currently doing zig on embedded (pi pico).
Please continue 🎉❤
In case you aren't aware, you can have zig set up a basic project for you with "zig init-exe" (or "zig init-lib" for a library project).
Yeah it's great!
You have great approach to dive in new lang, step-by-step, try do simple, run and test, do more... Super!
Thanks a lot for making zig videos! Really motivates me to learn it
Hi, I'm new to a programming language with manual memory menagement. I was wondering doesn't arena allocator supposed to free all memory it's allocated so you don't need to manually free each object? Here 30:23 the author defer deallocation of the read_buf which was allocated using arena allocator.
Came to the comments to make this exact comment
Subscribing because of zig, didn’t know your content cause I don’t use python. Great video, hope you do some more
Awesome! Thanks for subscribing.
I too have some zig tutorials more lowlevel stuff. Perhaps you’ll like that too, currently we are doing embedded programming on a cheap Pi Pico
Ziglings look like a fine place to start learning, but... having to learn based out dev version for someone that has no clue out to work with zig is not very good approach. I have the latest version of Zig and I can run ziglings because it requires some dev version. Anything that should be point out for teaching should always come from stable code.
Zig will be a moving target until 1.0. I played through Ziglings a year ago and then helped Dave update it. It's invariably out of date again. Maybe you can help update it too. You'll learn a lot, even if, especially if, the language changes (subtly). Because you'll have an educated opinion as to why.
Yea, it's a really bizarre choice for something that's supposed to be geared toward beginners
I haven't read through all of the comments to see if this has been mentioned or not... When you "install" a new version wouldn't it be better to keep the folders name as is and then just create a symlink call zig to the version you want? This way you can always reverence which versions you have downloaded as well as which version is in use.
couldn't you create a var "elfmaxamount" initialized to zero, then when doing the loop and hitting the line of length zero, compare elfamount to elfmaxamount, and overwrite elfmaxamount if elfamount is bigger, then zero out elfamount? This avoids ever using the array.
is there a way to read and process line by line in zig?
Nice content ! Thanks
Why compiler does not have at least warnings for missing deinit free and close
nice video
Great video thanks
Cara, eu também sou brasileiro e percebi isso só pela sua fonética! kkkkk
Parabéns mano.
He sounds quite British to be fairer
Julia language:
max_elf = current_sum = 0
for l in eachline("input.txt")
if isempty(l)
max_elf = max(max_elf, current_sum)
current_sum = 0
else
current_sum += parse(Int, l)
end
end
println(max_elf)
This gives the correct output in 10 lines of code vs. 43 lines of Zig. For a scientist, these verbose languages are out of the discussion. I think C is even better than this when it comes to time and effort required from the programmer. I'm not against the development of new programming languages, that's how new ideas are to be explored anyway, but I'm wondering why language features like memory safety are at the forefront of language design and the users (us) are a second thought? Maybe Rust is enough for those who have plenty of time to waste fighting the compiler? I hope more developers focus on the user first and try new ideas.
brew install zig
done ✅
is it for zigjag?
Nim-lang:
import strutils
var
accum = 0
elfs:seq[int]
for line in readFile("elf.txt").splitLines:
if (let amount = try:line.parseInt except:0; amount > 0):
accum += amount
else:
echo "elf ",elfs.len+1,": ",accum
elfs.add accum
accum = 0
echo "max elfs: ",max elfs
output ->
elf 1: 6000
elf 2: 4000
elf 3: 11000
elf 4: 24000
elf 5: 10000
max elfs: 24000
I love this language.. I hate their moto that is actually saying that the compiler contains a backdoor
Awesome tutorial.
will you add this series to a zig playlist?
Thanks for reminding me - I've created a playlist for the zig series
You are brazillian, right?
I _deviated_ to handle conversion errors :)
Why not using Homebrew for the zig installation? So much easier.
Nice start, until 6:46 I somehow lost the apetite.
Where is second part
ruclips.net/video/BYy2Y8K57XE/видео.html
I absolutely don't understand the allocator code that you wrote. C's malloc makes more sense to me then what Zig does. The way malloc can be used to allocate memory is much more simpler. What is this ArenaAllocator that you create with page_allocator? It looks bizarre and I don't see an explanation here. Zig's syntax looks like an unholy marriage between Java and C.
I did a bit of googling and I wrote this program without all this memory allocation for the file handling. I used bufferedReader and stuff and it probably allocates memory in the background, but at lease I understand what the code does.
Spoke too soon. I did end up creating an allocator for the ArrayList. Not the same allocator shown in the video though. I used this one -- std.heap.GeneralPurposeAllocator(.{}){};
Copilot and ChatGPT got othering? You don’t say 😂
For my define video I created a Game Genie NES code generator and I figured let’s ask Chat Jippity to see if it can optimize my code a bit. It took my code where I have an array that translates hex to GG characters and turned it in to an if the else tree 😂and that didn’t even compile on Zig. I kept telling it that an operator it chose did not existing zig. But it kept hammering on 😂I then figured let’s just optimize my bit shifting algorithm the bit wide operations in zig are identical to C so it must be able to…. Yeah totally screw that up as well 😂I don’t want to use either of that crap. It’s so bad!
How is this easier than rust 😂😂😂
hard to get enthusiastic about a language when the getting started guide is wrong and doesn't work and the example code won't run when you follow the instructions to build it.
and there's virtually no documentation about it.
zig has potential... but god damn, its ugly and verbose.. []u8 as string? da fuck? passing anonymous struct to print even when u don't pass any argument? list goes on.. odin should get more love.. better language
If you think the potential it has is something contingent on resolving this ugliness or verbosity though, then you are mistaken. Because these are the result of the fulfillment of the languages design goals. There is a WHOLE lot of discussion about these decisions in the issue tracker though if you don't understand the motivation behind them, and given how much discussion when into many of these decisions, they aren't likely to change substantially.
I don't think odin is a better language. I like odin though, and I think it is probably the sanest newer alternative to zig for people who feel this way about it.
Absolutely agree, not a fan of zig after seeing this. Way to verbose, no thanks. Expert level will ALWAYS be simplicity, this is not that.
I don't think you're experience enough to teach programming
He is a great communicator and did extremely well! It’s a privilege to have access to high quality content like the one we have here. It might not be your style but being negative and not providing constructive criticism is just a sign of lack of respect to yourself as a learner. Learn to learn, start with the basics and be polite.