Zig programming language tutorial - Part 1

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 55

  • @CallousCoder
    @CallousCoder Год назад +15

    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”.

  • @squ34ky
    @squ34ky 10 месяцев назад +3

    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.

  • @pcost
    @pcost Год назад +13

    Just found out your channel, and that's an awesome tutorial, keep going Matt! Got a new follower and fan!

    • @CallousCoder
      @CallousCoder Год назад

      I also have zig videos currently doing zig on embedded (pi pico).

  • @shubhamkumaranand6398
    @shubhamkumaranand6398 Год назад +7

    Please continue 🎉❤

  • @sakuyarules
    @sakuyarules Год назад +3

    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).

  • @alexdubkov6998
    @alexdubkov6998 11 месяцев назад

    You have great approach to dive in new lang, step-by-step, try do simple, run and test, do more... Super!

  • @enzocalzone5298
    @enzocalzone5298 Год назад

    Thanks a lot for making zig videos! Really motivates me to learn it

  • @vadymbarabanov156
    @vadymbarabanov156 11 месяцев назад +2

    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.

    • @duke605
      @duke605 11 месяцев назад +1

      Came to the comments to make this exact comment

  • @churraskindequeijo8418
    @churraskindequeijo8418 Год назад +1

    Subscribing because of zig, didn’t know your content cause I don’t use python. Great video, hope you do some more

    • @mattfreire
      @mattfreire  Год назад

      Awesome! Thanks for subscribing.

    • @CallousCoder
      @CallousCoder Год назад +2

      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

  • @pedroluzio
    @pedroluzio 11 месяцев назад +4

    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.

    • @familyshare3724
      @familyshare3724 9 месяцев назад

      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.

    • @Halfbit_0
      @Halfbit_0 5 месяцев назад

      Yea, it's a really bizarre choice for something that's supposed to be geared toward beginners

  • @JacobMilesmilesje
    @JacobMilesmilesje 9 месяцев назад

    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.

  • @Negi2468
    @Negi2468 Месяц назад

    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.

  • @knowledgedose1956
    @knowledgedose1956 Год назад +1

    is there a way to read and process line by line in zig?

  • @monsieurdoz8695
    @monsieurdoz8695 Год назад

    Nice content ! Thanks

  • @severgun
    @severgun 3 месяца назад

    Why compiler does not have at least warnings for missing deinit free and close

  • @yuridelossantos569
    @yuridelossantos569 10 месяцев назад

    nice video

  • @jjpell
    @jjpell Год назад

    Great video thanks

  • @victorpinasarnault9135
    @victorpinasarnault9135 Год назад +3

    Cara, eu também sou brasileiro e percebi isso só pela sua fonética! kkkkk
    Parabéns mano.

    • @kanji_nakamoto
      @kanji_nakamoto 5 месяцев назад

      He sounds quite British to be fairer

  • @valdarbien3252
    @valdarbien3252 9 месяцев назад +2

    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.

  • @limitlesskode
    @limitlesskode 7 месяцев назад

    brew install zig
    done ✅

  • @kkang-aji
    @kkang-aji Год назад +1

    is it for zigjag?

  • @megetmorsomt
    @megetmorsomt Год назад

    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

  • @alex-costantino
    @alex-costantino 7 месяцев назад

    I love this language.. I hate their moto that is actually saying that the compiler contains a backdoor

  • @7heMech
    @7heMech 11 месяцев назад

    Awesome tutorial.

  • @eduardabramovich1216
    @eduardabramovich1216 Год назад

    will you add this series to a zig playlist?

    • @mattfreire
      @mattfreire  Год назад

      Thanks for reminding me - I've created a playlist for the zig series

  • @victorpinasarnault9135
    @victorpinasarnault9135 Год назад

    You are brazillian, right?

  • @OghamTheBold
    @OghamTheBold Год назад

    I _deviated_ to handle conversion errors :)

  • @martinmajewski
    @martinmajewski 9 месяцев назад

    Why not using Homebrew for the zig installation? So much easier.

  • @diynevala
    @diynevala 11 месяцев назад

    Nice start, until 6:46 I somehow lost the apetite.

  • @rajapriya7663
    @rajapriya7663 Год назад

    Where is second part

    • @IamPyu-v
      @IamPyu-v 8 месяцев назад

      ruclips.net/video/BYy2Y8K57XE/видео.html

  • @dexternepo
    @dexternepo 6 дней назад

    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.

    • @dexternepo
      @dexternepo 5 дней назад

      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.

    • @dexternepo
      @dexternepo 4 дня назад

      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(.{}){};

  • @CallousCoder
    @CallousCoder Год назад

    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!

  • @chouaibjolcen-uj2iq
    @chouaibjolcen-uj2iq 10 месяцев назад

    How is this easier than rust 😂😂😂

  • @axeman2638
    @axeman2638 8 месяцев назад

    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.

  • @_slier
    @_slier Год назад +2

    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

    • @homelessrobot
      @homelessrobot Год назад +1

      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.

    • @lmnts556
      @lmnts556 Год назад +2

      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.

  • @0xc0ffee_
    @0xc0ffee_ 7 месяцев назад +4

    I don't think you're experience enough to teach programming

    • @kanji_nakamoto
      @kanji_nakamoto 5 месяцев назад +7

      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.