Trying Zig Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so the goal here is that once a week for about two hours I will learn rust or learn rust we already did that I'll learn Zig and we'll just kind of go through and kind of just like look at it a little bit at a time I think it's going to be a cool kind of exploration because I know a lot about it and then we'll do like some sort of language exploration every week uh Ginger bill is here creator of Odin maybe after doing uh you know maybe 10 weeks with Zig we'll do 10 weeks with Odin you know kind of do like a uh you know take take like just two hours a week and kind of go through it what I'm going to build in uh Zig will probably be the exact same thing I'm building right now so what I'm building right now is this idea of an ASI engine but I've kind of changed up a lot of stuff the ASI engine I I really after building one myself and then trying to Port Doom asky into something that I can build with with uh go and make it distributed what I realized is that I made a couple mistakes so there's some things I really want to do so here's the overall project that I want to build I want to be able to take um I want to be able to take ansy right we're going to take in anti- encoded string and we're going to convert that into a bite buffer and I realized my mistake here I'm going to convert it into two bite buffers right one will be the characters the other one will be the colors all right the reason why is the following is that then we're going to take this bite buffer and we're going to run uh we're going to run rle on it and maybe we'll look at like some Huffman and codings we we'll do some stuff that's going to be pretty exciting okay but the reason why is that if you really think about it here let me let me open up uh let me let me open up uh Doom really quickly all right so watch this for a second so what I want you to notice is that as he runs around and as he turns as this guy takes one step forward the colors will all shift down like one bits but all the asy horizontally will change a whole bunch so the general idea here is that I want to have two different encodings for these bite arrays the colors I'm going to use something like a quad tree that I will go maybe two times in who who knows we'll we'll we'll find some sort of sweet spot and I'm going to encode this box with rle on the color bits but how I'm going to do this is not via that what I'm going to do is I'm actually going to take the previous buffer and the current buffer I'm going to X or them and then I'm going to encode the inverted change I'm going to encode the inverted change and run rle on the inverted change so this would equal the final buffer and the final buffer I will be taking little squares and doing RL on cuz a lot of it for the colors won't change I mean it's only eight bit coloring so it's like there's like these step functions of change that it has to go through and so we'll be able to do stuff and I'll see how well that I'll see how well that actually goes I'm pretty sure Prime's losing 90% of chat right now I'd actually like to think that chat can understand that I don't think that that's CR I I I don't think that what we're talk about is that crazy so this is the general idea for the goal of of of this a run run length en coding is super super simple you know it by default let's pretend like you had this the following string wwwww d w w w w what you could say is this is 4 w d or 4 W 1 d 3w does that make sense run length en coding is really simple so as you could imagine if you do a buffer the previous buffer you exor it with the current buffer you're probably what you're probably gonna get for colors is you're going to get large portions are zeros and maybe the edges are nonzero nonzero so rling the box as opposed to the whole line is probably going to be really efficient is my I we're guessing here so I want to be able to run these different things whereas the characters are probably better to rle as a line as opposed to as a box so we're going to make some we're going to make some like guesses here and see how that goes then the next thing I also want to do is figure out can we run a Huffman en coding on it and then I had this I had this other idea which is the Huffman and coding check this out I think this is a good idea you take the Huffman encoding and what you do is you measure the percent of change during exor so if we have a low percentage of change in exor let's just say that we'll call low percentage for now this is just a guess we'll call it less than 10% but my Huffman encoding good encoded bits is say less than some percentage whoopsies there we go say my Huffman encoded good percentage of bits because remember bad bit en coding with Huffman is bigger good one is really is is much smaller let's pretend we had that and let's just say that that that one we're like we're getting really bad results with really bad Huffman and coding results with if we have a low change and a low success Huffman and coding can we regenerate a new tree and try this idea of static Dynamic trees or do we call it Dynamic static trees right like an ey frame kind of like an eye frame so these are all my thoughts in my head of can we make it's kind of like having an eye frame it's kind of like having an eye frame every single time there's a bunch of change we know there's a bunch of change and there's nothing we can do but if that change normalizes for a second recalculate send down the new tree and say this is your new tree you're going to be using or even more so we calculate a set of of Huffman trees and the beginning bite says this is the tree to use I'm not saying that would be a good idea because I think computationally this would be a nightmare to run but it'd be cash Madness right at right I saw Ginger Bill coming here on Ginger bill I need the I need the there you go so there you go that is that is my general idea uh it's already a thing you can add add whatever and you can write your own little uh meta program oh okay that's a little Odin thing thank you no no you need to be VIP you're you you actually are building something real need true frames from time to time see I don't think I need technically true frames for this I'm not sure if I do I don't know if I need true fra frames yet have you seen the the let versus con uh Twitter news cycle can you link it to me it started I can you can you link me a couple of them I do I do actually want to look at that but we're going to start off with zigg then we'll do some news articles I have one on llms being uh people are using llms for uh encoding and it sucked welcome to the Diamond Club Ginger bill it makes you forget uh let's see it makes you a target for Nightshade dude though careful it's true look at him he got banned what color type will you be uh will you use for the project I'm not sure what that means I don't know what that means all right so let's get started with Zig uh I I I do want that I'm going to try to keep an eye out for that uh link as it comes in uh since since it's lossless that's why you don't need uh true frames it is lossless so yeah you don't need I don't need true frames the moment it changes and my encoding is no longer good then either I do a new encoding or if it's too not encodable we just simply don't encode it and so I'll need some way to kind of say like use or don't use Huffman encoding right okay so you get the idea so let's start with Zig it's also the reason why if you didn't know I uh I did a I did a color scheme change for this for this little thing all right maker uh zigging there we go all right so let's first install Zig I don't have Zig let's go uh let's see download install Zig is there is there a nice little is there a nice little sh script I can just just throw into into here Port dude they have all those things you want to build from Source let's build from source that seems more fun all right why build from Source the primary reason to build from source is in order to participate in the development process of Zig itself oh interesting okay is there is do we just have a nice package manager for Linux usually anything you do with um where's Debian I can't read this where's Debian Arch Arch Arch Arch Arch Arch Arch Arch Fedora Fedora Fedora Fedora Fedora gentu gentu Homebrew kiss Mac porch stable next package opens pack install scooops do we not have it on there it has no D just use uh pip uh download a pre I know we just do a pre-built package but I just wanted all right what's the latest one we can use Windows Max let's see uh what can we use here this one is this fine is this the latest what is this one oh this is just Master they do have 12 should we use master or should we use 12 hey thank you y why for that tier one three months in advance probably just use 12 huh it's probably a little bit more reliable yeah we'll use 12 12 for now 12 is probably the the way to go all right there we go and now time for that time I tar things and I never remember how to Tar things Z is z compressed or uncompressed I can never remember how to uncompress something every single time you know I should just learn this I honestly should just learn this but I have just I've been oh tar XZ how do you tar XZ which one which one is a which one is a tarx z ah ah uh tldr uh tar dud I always forget this every single time hey thank you very much for that I appreciate that dude I dude I forget these things Lil Bon part thank you for that that and a that tier one that gifted tier one and K hatching thank you for that resubscribed just started learning sick as well I'm loving it nice all right so we just had to do uh let's see create an archive no do every single time extract okay so X means extract okay X means extract so I should be able to do this effectively tar x file to directory does that seem good I think that seems good so I don't know what is oopsies uh every single time every single time and I just need the prevented okay this makes sense so let's just tar XF uh downloads Zig uh Zig 12 and then directory and then we'll put it into Zig I always forget how to xct funny I always forget how to press dude I can never remember any of these things all right uh ls- La uh Zig just we'll just go find Zig okay nice nice nice is it not is it not that or is it oh is it executable okay so we do have a little Ziggy right here so I should be able to just go uh can I go like this Zig uh can I just hit him with the zig nice there we go we got ourselves a little bit of a zig version version okay there we go we got a zig we do got a zig do you plan on uh wrting something specific with Zig or just exploring I just got done explaining exactly what I'm going to be doing um yeah so like exactly went over the whole thing so there we go so I like this I think this is good this is what I want to do um all right we got to get this on our path now um let's add this to path actually before I do that uh Zig can I just move uh what's in here to Here There we go that sounds good yeah yeah uh zish profile there we go good good yeah oopsies uh what where are we at we're at uh zigging there we go and then let's go there we go Zig okay perfect all right we're back in hey Chim trimo trimo thank you for that tier one let's go let's go Chim all right so we got we got Zig all you already have an entire an entry for Zig in the path by the way oh I did did I just not even see that oh I did I did who would have guessed I already did this who would have guessed already did this pre-at pre-coded pre- everything absolutely uh there we go well yeah because at one point I did have Zig I did have Zig we did like a basic exploration of Zig all right so let's just getting started with Zig I don't know how to get started with Zig I want to try to learn this the proper way okay getting started all right so we we have the installation recommended tools all right syntax highlighters and LSPs yeah absolutely I do want some tools all major text editors have syntax highlight support for Zig some bundle it some requires an installing a plugin if you're interested in a deeper uh integration between Zig and your editor check out Zig tools zls okay let's start there zls all right in ation get clone this one okay this should be pretty easy the old G clone get clone destroying it what was it it was it just Zig build you must do it for that version Oh Oh requires this version oh okay uh get uh tag okay uh get check out zero that's cool how' I do learning Zig to use it uh for some part of the games just to learn Zig I've been wanting to do the zig zls has gotten so much better since 10 okay that's good to know cuz I used it at 10 for a moment notorious Sledge thank you watch lowlevel learnings latest video on Zig I did uh yxk okay there we go we're doing this thing I missed the go compile times already uh the yeah 10 was rough 10 was rough so yeah so that's why I'm curious now okay so we're going to just build Z did something happen since you changed your colors yeah we've changed our colors I want to make this darker but I'm just too lazy to go figure out uh how to do to do it with alacrity man we are we are building we are just we're just building we're only using one CPU though can we use more can you give me all the CPUs or is this just not possible to do in parallel there we go okay ls- La uh is it Zig out that must be where where it went to there it is okay oh I know real question is the following um actually when I when I was in uh when I was in zigging and I went like this yeah I could have done zls there we go that's nice here since we're here let's let's update our little uh let's update our little items here uh they should have uh called the output zag they should have if they were smart they would have called it zag okay there we go so we got that done okay so we got our little we got our little we built it it was easy to build no problems there everything okay so everything's going pretty smooth so far all right if you've completed the installation process correctly you should be able to now invoke the zig compiler from your shell yes which we did okay Zig it it well let's ziga zaga uh an it there we go running Zig build should run and let's see should run then compile or should uh compile then the execut then run it okay Zig build run all your code base are belong to us nice Zig build test I remember Zig Zig back in the day built really fast things must have slowed down a little bit since when I looked at it in its very early days to now is that true all right next steps uh are you going to give Swift a try at some point in the future yeah that we're going to do that it's much slower like 3x okay so that's what I thought I thought I was like I I feel like it's it's much slower than it was interesting interesting interesting okay so that that I'm going to put that in the negative box uh the first build is always slow because of llvm but it gets much faster not by much okay well lowle learning I remember at one point it was it felt faster than this yes I know everyone says the build system in Zig is the place to be all right let's see check out other resources uh pres uh present in the learn section make sure the documentation for your version of Zig okay Zig is a young project and unfortunately we don't have the capacity to produce extensive documentation and learning material so everything should be considered joining one of the existing Zig communities all right there we go so let's look at the learn let's look at the learn stuff let's do um I guess we should just start we just start where we can hey jerl thank you for the five gifted Subs jerl appreciate that isn't Zig planning to have their own uh instead of llvm not anytime soon though um I think so I I remember there it was something about them separating out from llm all right Z is General Pur uh purpose programming language and Tool chain for maintaining a robust optimal and reusable software all right let's get through that the zig standard library has its own documentation okay let's go uh Mamon appreciate that twitch Pride that t twitch Prime all right it has its own zigging is zigging the place to go okay let's go to zigg Lings I feel like I've done I feel like I've seen this before uh get clone zigg Lings you you like build it to build a test over and over again right intended audience uh let's see this will produce you'll never Pro let's see let's see this will probably be difficult if you've never programmed before but no specific programming language is required okay getting started Zig version clone this Zig build okay so I guess I just start something tells me that this is a little bit different than the one I was on do I need to go to 11 oh it said the project has moved oh attention the project has moved to codg code BG what the hell's code BG is codg just like inconvenient uh uh so still installing Zig no I'm not installing Zig I'm trying a supplemental learning there is no tracking information with the current Branch uh get get Branch uh there we go um how do they diverge how did we diverge all right there we go okay we're in we're in we're in all right all right the following command failed with compile errors uh route. main uh what's happened here called from here called main main called from here uh let's see referen by this zigging hint Don't Panic read the compiler message above something about main open up the source okay we'll do it we'll do it exercises uh all right what do we got here whoa why is why did writing take this long where did I go what the heck just happened here oh that was crazy it like completely blocked the system there for a second I know I I know there's something going wrong here I can see it I can see it I can see it um H is there a way to with Mason is there a way to see where it was installed at okay installed version 12 so this is I mean this is good it does not zls moment it does not in it does not run it on the on the main thread that's not even how these things should work like you can't run that on the main thread in the mson folder okay so but it looks like it has the right version right it install let's see install Dev no I don't want to install Dev 13 because I have Zig version 12 there we go you know what I mean there you are okay version 12 okay so we did get that did you try adding water to it hello Chad hello Prime no I'm too lazy to install Zig there we go all right so for whatever reason trouble doesn't work with it so so there's obviously there's something going on there that I don't know whoa uh what video game is this the graphics are amazing thank you uh cron spiral let's go or is it con con spiral thank you all right so let's let's look at just the error then all right all right function so I don't let's see oh look at this main is not marked as Pub okay so you have to mark things as Pub okay okay okay that's not too bad it's KRON spiral now it's chronic spiral thank you Amir appreciate that tier one 18 months thank you okay well apparently is disabled for zigging it can't be disabled for zigging is it really disabled for zigging oh is that why Okay zigging Main Branch says use 13 oh is there a get tag is there like a version 12 get check out V this okay cool yeah yeah yeah yeah yeah yeah yeah yeah uh 002 okay nice okay so now there we go so now we have this oops the program uh that is supposed to print a line like Hello World example but forgot how to import Zig standard Library import function is built into Zig it returns a value which represents the imported code it's a good idea to store the imported code as a const variable const fu fu okay so I'd go const standard and then we go standard debug and all this cool I can jump nice okay cool cool okay cool cool cool cool see we got a little carried away making everything cons du eight okay good con cannot change let's see values cannot change uh types are unsigned yep and cannot store negative values eight means eight bits for example food cannot change it's constant bar can change it's variable yep cons Fu ver all right um Fu cannot be negative yep okay so I feel like I already know all these things so I just should be able to look at this what's the air all right so there you go there's that problem all right air type UA yeah UA can't do that so let's see how big is this so that should be what a u a u at least at least a u a u19 minimum L i19 there we go look at that look at that u19 so easy u9 aware yeah what a great segue yeah 9 so yes so a zig you can specify any bit with I know a lot of you are laughing but I want you to think about this for a second why would arbitrary uh Precision be good especially at a systems level language that's so cursed hold on hold on I don't know how to do it yet but I know that this exists where you can do something like struct Fu I I don't know what the exact things is but you could imagine that one could do you know like um one could go version is a U2 you know then the next one could be encoding could be a a u4 right so I've already have that too then I could have like maybe um uh Huffman you know use huff and coding U1 and then I could have some you know other flag you won like you could imagine I could do something like that like something like C allows you to do this right c c it just feels wrong see see right this this isn't uh this isn't something new right it's presumably it's going to be presumably it's a you the size of your system right is my my assumption yeah so I I don't quite know hold on I got this other microphone right here I want to put it back over here I can't really read the chat very well without it you back on the Kinesis I am uh is it actually bid packed though that I don't know so that's actually interesting I don't know how it's bit packed that's a good it's a good question uh code links there we go all right but anyways whoa do we still have a problem there we go four uh 004 hey appreciate that appreciate that sub by the way code links okay so we're just going to go through this one at a time let's learn some array Basics arrays are declared with this one okay size size okay fairly goish uh when Zig can infer the size of an array you can use underscore okay cool uh values of an array using array index notation okay values of an array using can can you invert them can you invert them like C uh the set the values of an array using our array index notation and get the the length of an array using the length property okay length cool okay so that's all pretty straightforward so we have this thing which already has a bunch of primes got them some primes two uh let's see 0al 2 which will remove one uh individual values can also be accessed with this yep first uh looks like we need to complete the expression use the example above to set the fourth element uh I never know is is four three so that would be length right yeah oh interesting oh nice it's a proper constant we got ourselves a proper constant prime prime I sorry I just read uh one is not a prime I just read that and then said my own name Thor's watching you again why is Thor watching me we're just looking at we're looking at Z Thor by the way I is riffing on a Thor at home clip okay okay okay guy hey look at this Thor if you're watching you see that that what is this oh so much manliness anyways you wouldn't get it you wouldn't understand you wouldn't understand see I can do voice changing as well too bad his mustache is fake okay okay shut up shut up that guy uh 005 all right zigg has some fun array operators you can use Plus+ to concatenate two arrays okay I don't I mean I don't love that stuff but okay this can be really nice the bots in YouTube chat what's going on there I didn't even look at what's going on in YouTube chat do we have like boobs or something boobs and dicks dicks and boobs no one knows anything we're all at different levels in each thing never room to learn them all get good at finding answers through old questions and thoughtful I would normally think this is a bot but there's not like an ass photo this is a very this is a it does feel like you wrote this with an llm Thor called your mustache fake or it's made of Marmite okay Marmite that's uh that is offensive okay okay hey Lil bonapart thank you for that gifted sub that's that's offensive okay you can use star star operator to repeat an array very python very python note that both Plus+ and star star only operate on arrays while your program is being compiled okay so you must not be able to use this in uh so so Plus+ and and star star can only be used on on well-known arrays okay this makes sense that makes sense that's actually super cool we nut I appreciate that twitch Prime okay so that makes perfect sense okay so we're on to this we're on you so this is like this is just comp time information Bastion appreciate that Bastion let's go Bastion did you know that there's some other person named Bastion that also was tossing out gifted Subs look that no Dynamic allocation nice okay so this is only static allocation okay this makes sense this is cool uh Le should result in that so that should be Elite uh right Elite cool bit pattern uh yeah cool okay okay that that was kind of nice that was kind of nice I like that okay hey now that we've learned about arrays we can talk about strings uh we've already seen Zig uh string literals hello world okay zig store strings uh as a raise of bytes all right uh it's almost the same as this almost I wonder what the almost is we'll see uh what Zig strings really are in exercise 77 oh jeez notice how individual characters use uh quotes Okay and strings use double quotes okay they're not interchangeable okay so like standard just standard string stuff that you'd come to expect uh I I assume the difference is is that Zig treats a string as some sort of managed type or managed string that has like some sort of encoding requirement maybe is it utf8 required or is it just simply go for it required but it probably has dot length it has some things is my guess they're constant u8 slices okay so they're they're much more like just they're just much more like C okay cool I like that notice how individual characters okay yeah let's see what do we got here problem one all right Ziggy start Stardust okay use an array bracket syntax to get the letter D okay I think we can do that uh that should be uh four right and I get this right I think so let's see repeat the array haaha Okay cool so you can Times by three that's cool okay you can do that you can do the exact same thing you can do Major Tom we can Con cat we can cat them right okay print USS D major okay you must be for what What's d DZ u8 okay so d deep okay use for the unsigned int s is for the strings hey printing has gotten a lot nicer and S oopsies nice let's go is this is a natural Pas time that all people should be okay with hey uh trap I appreciate that Community sub everybody can I get some can I get some W's are there exercises for this like go I'm not sure if there is there might be go Lings go Lings might be a thing okay let's keep on going let's see you can make a multi-line string by putting SL slash at the beginning of each line oh okay I mean I don't I don't love that but whatever it's just it's just syntax at the end of the day whatever quiz time let's see if you can fix the whole program you'll have to think about uh this one this one a bit let's okay see see note uze is an unsigned type for uh type used for sizes the exact size of the uze depends on the target CP yes okay so this is like C or C++ okay we know all about the MU sizes um but usze is the idiomatic type used for indexing arrays there is a problem on this line but usze isn't it okay we'll see how it's used later on I don't know why it's a problem we haven't figured out why that's a problem that looks that looks completely fine to me but let's keep on going all right note that when you declare memory and array in this case without uh putting anything in it you can set it to undefined there is no problem with this line okay so you can just have this thing hasn't been set yet the following lines attempts to put z i and Zig into the Lang let's see into lay array just as we decare let's see created the index above uh with variables X as you can see x1's begin with Okay so this should fail right I assume this would fail no undefined is the is the zero right this thing creates zero right undefined creates zero correct maybe let's find out x equals 3 okay uh so you want a VAR at that point all right the following attempts to do these things so we go letter X uninitialized oh it's just some uninitialized not defined yet okay okay it's just uninitialized memory in that location all right Lang 0 equals that x equals 3 what what the heck is three 0 1 2 3 okay 0 1 2 3 4 5 did I do that correctly easy easy I think undefined creates garbage no undefined creates the memory it just doesn't allocate it doesn't uh it doesn't initialize anything right uh in the bug it generates 080808 that's right okay that's right I okay I remember seeing that allocate no in it yes okay it allocates with no in it that's right I've seen this I've seen this okay okay so is undefined a type no I think undefined is an operation maybe it's better to say right because undefined creates the memory space for the item and fills it into bug mode with uh uh 0 one01 01 01 or one 0 one 01 0 1 0 which is yeah why not have AAR garbage keyword well it's not garbage it's just here's memory it is a garbage it's literally a garbage it is it similar to null no nothing similar to null null null if you if you said null uh you're effectively setting it to that right you set it to zero which is like the invalid memory space all right all right so let's go to an if statement uh 9 all right Fu equals 1 so we can't do that okay yeah that makes sense that that just easy stuff there all right um oh what is this uh please use an if else expression to set the price okay okay okay what do we do let's see the price should be 7 otherwise 20 if discount 17 else 20 oh it enforce oh I am always sad that it enforces that stuff I'm not a fan you know I I I'd rather see it enforce these then enforce those whatever all right we're we're we're cruising is that the Kinesis right yeah I'm on the Kinesis things are getting functional we're getting we're getting close all right Zig while statements uh create a loop that runs while condition uh is true okay anti- functional let's see please use a condition to set uh that is true until n reaches 1024 okay while n is less than 1024 I assume that's just what they want all right while statements can have an optional let's it can have an optional continue expression which runs every time wa which runs every time the while loop continues either at the end of the loop or when explicitly continue is invoked oh okay so this is like okay okay so this would be uh I'd go n uh equals uh time equals 2 cool okay so all right so that I mean that's equivalent of like a four statement okay okay I get that I get that the last two exercises were functionally identical continue Expressions really show their utility when used with continue statements okay condition continue expression other condition continue the continue expression executes every time the loop restarts whether the continuous uh statement happens or not all right uh I want to print every number between 1 and 20 that is not okay so I have to go continue okay cool Reinventing Loops I'm not sure if it's Reinventing Loops love the name uh I sense a fellow brother dish pit Dev oh nice dog water Dev dish pit Dev they're friends they're friends right there uh someone just had a bad time with fizzbuzz someone just had a bad time with fizzbuzz is the glove 80 worth it uh I I will be I'll be doing a review here soon recorded a lot of footage for it all right oh dear uh this Loop will go on forever please fix it so that this print statement below gives the desired output okay so this is break result we want n equals 4 okay so I can go if n equals 4 I assume break works okay so break break is break is standard break is standard so that's nice to know null hey I appreciate that tier one thank you uh what projects are usually applied to Zig my my assumption is more is going to be much more systems level programming than anything else I think there's a benator for Hardware level stuff yeah all right what's this one behold the for Loop uh Loops let you execute code in an element of an array four items item okay so here's this one HH SNH okay so I should be able to go um Story scene I do like this this is cool I'm not sure if I prefer four I a scene in story I kind of feel like I'd rather do that I kind of wish they Ed that yeah yeah okay we had the exact same idea here new language new color scheme you know we got to change things up you know we got to we're feeling it we're feeling it you know it's just one one thing at a time one thing at a time all right what do we got here we'll convert the binary bits to a number value adding the value of the place as a power of two for each bit wait what for Loops also let you uh use an index of the iteration a number that can uh counts up with each iteration to access the index of the iteration specify the second condition okay let's see where do we got this thing hold let me look at this okay now we'll convert the binary bits to a number value by adding the value of the place as a power of two to each bit yes see if you can figure out the missing bits all right so we have this one cast in cast ey so I assume this thing right here is just a oh it' be um start at zero no for oh is it is wait on is the first level thing length oh what's this dot dot oh for zero up until oh is that what that is so if I go like this hold on so if I go uh can I do that length one here nice nice so I can do up I can explicitly State four or I can go like that to do that does that mean I can go like this how do you print nice can I do um nice cool cool okay so you can do range operators range operators are available can you reverse it good question it just says it terminated unexpectedly so they must be hiding the eror from us I'm curious how that would work anyways all right well that's pretty neat they're hid in the air we' probably could expose the air and just by doing you need you need a while for the reverse you need a while for reverse okay that makes sense I mean that stuff is difficult to do all right command failed uh 17 let's see all right 17 import standard library right that's just a oopsies uh what are you import standard right uh that's Pub function main right do we get that one uh this is a while loop I can tell by the way it is let's see what kind of loop is this for a while you can tell by the way it is Fizz Buzz I we don't have to use that though let's see print um I pretty sure I did that right first tried that quiz first try that quiz come on okay so I feel like I kind of got it you can do value one value two negative 1 oh really oh really let's go like this um yeah I don't know if that's a I don't know if that's a thing I don't think you can put a step in there do you know what's better than a while loop what night shade dude W these nuts rest on your chin look at that I already called it I pre-call it pre-call it this is just a capture value dude I like how I I have done less than one hour of Zig did you abandon go let just let let them if someone does something for one hour maybe it's just for one hour sometimes a cigar is just a cigar uh functions we've already created uh lots of functions called main now let's do something different four function Fu eight returns eight okay let's see let's see a new function deep thought should return number 42 okay so if I'm doing this I should be able to do a function that returns a u8 yeah because it it expects a u8 okay all right um let's see how do we use it uh let's see Powers it two 1 two 3 four okay so my assumption is we'll do a um what do we call my number uh u32 okay yep got that one 20 it's a quiz let's see if we can make use of some of the things you've learned so far okay all right let's see what the main is Con my numbers these things print powers of two my numbers ooh okay okay print powers of two Loop four that's obviously a four Loop right there takes in a U6 and it returns out void doesn't return out anything uh uh to the uh two to the this function uh Bears a striking resemblance to to to the wait oh in the last exercise don't be fooled this one does a math without the aid of a standard Library okay so this one looks like a while loop right does all that and that's a total and we need to return out what appears to be a U6 dang owned that quiz dang dang I am just I'm a zig I'm a zig I'm a zigger we're we're we're flying boys yeah yeah we're we're we're going pretty fast we're going pretty fast cigar mentioned you just link Star Wars from a a Star Trek reference wait what the hell is this I don't even recognize this person it is a period of civil lawsuits I did not have sex with that woman Miss Lewinsky damn Star Wars okay okay okay that's pretty cool that's pretty good I did not I did not I did not all right so let's keep on going um I like it I like it oh look at this this a zig cash listen what's that thing all right airs oh we're going to get into airs let's go airs are a really great airs are really great oh I have that really loud welcome to Costco Rock respawn appreciate it Thor's on the side while Prime codes is this love it could be baby don't hurt me all right what do we got here Believe It or Not sometimes things go wrong in programs in Zig an error is a value errors are named so that we can identify things that can go wrong errors are created in error sets which are just collection of named errors we have the let's see the start of an error set but we're missing some conditions too small please add it where it's needed okay uh let's go 11 down uh too small all right um we still got some more issues all right let's look at here we get we get one of these we standard print this one uh number fail number error if uh number error equals uh my error too big we do this one um uh too small we do that one error 24 it's just error 24 Okay cool so we can do it looks like it's like a basic it looks like a basic enum I can see why people I mean I can definitely see why you want something you know like how they talked about doing something like that or a usze like adding a type to it I can see why you'd want that that makes sense to me like that does make sense to me Joey P pascetti appreciate that rock respawn no exceptions no exceptions just way too four yeah too small is what uh they all say yeah payload uh payloads are a foot gun in my opinion are they I don't know I don't know about that buddy I don't believe you um let's see compiling this thing let's see uh the following command uh failed let's see hold on let's see eror let's see number 22 errors two okay let's do that let's look at number 22 all right what do we got here let's go uh let's see I don't know what to do with this one hold on what are you doing here a common case for errors is a situation where we're expecting uh to have a value or something that has gone wrong uh yes I like this take this example text get text Fu what happens if G text can't find text Fu or Fu text oh hey thank you very muchin sein I appreciate thein and Mystic ninja thank you also for the twitch Prime lot of twitch primes today thank you yeah we'll probably do something we'll do something like that here soon Zig uh let us make what is called an error Union which is a value which could be either a regular value or an error from a set okay my error text get text okay okay so I should be able to go like this I should be able to go uh my number error unioned with a not a u size uze seems pretty nice got him all right 23 one way to deal with an error unions is just to catch any error and replace it with the default value so Fu can fail catch and return six okay can't fail Okay Okay cool so this is like an ore or whatever you'd call this thing so if we uh add 20 what does add 20 do if n is less than five return too small else we had 20 okay so we technically don't even need a catch here but if we remove that this wouldn't be right right I assume that this wouldn't work if we did that here let's go like this um my number error bang uh u32 my guess is that this is going to fail because this is actually a it's actually that type right now yeah yeah yeah yeah yeah yeah yeah yeah see look air too small okay cool okay cool we get it you think really you think that that's ugly I don't think that looks ugly that looks that's fine with me like I mean there's also this syntax I mean that that that's fine with me all right catch and can we do 69 is that an available item or is that just going to be no no no no no no no oh that worked wait what oh yeah because catch 69 this one will be uh this the number is not too small so it does add 20 no matter what okay nice catch 69 the syntax is confusing why what's confusing about it so far so far this all seems like pretty just straightforward syntax I mean I you have to go into every language and expect it to be different than the language you know hey Broski appreciate that and so like if you're not if you go into a language and expect the syntax to be the way you expect it like you're always going to be upset so what I do is I just go into it and I go okay how how do I express myself right ideal language you start typing and it works that is not an ideal language that sounds chaotic and horrifying it's called English have you ever worked with product people hey thank you five gifted subber I appreciate that let's go have you ever worked with I appreciate that thank you I wish I could say thank you to a real person but I can only say thank you to a ghost but real talk I want you to take like I want you to take that just take what you say to to to to an extent your ideal language is you start typing and it works okay so why is communicating with a product manager so hard are ghosts real this is such an interesting question watch this who here thinks ghosts aren't real like ghosts are not real one in the chat okay okay lots of ones lots of ones now this is where things get really interesting are you ready for the really interesting things watch this preferably everybody that typed a one type again do you have a ghost story there's going to be ones in there here's the weird part about ghost we collectively all believe that ghosts do not exist generally speaking you go into any group of four people and you say do you believe in ghosts and they'll say no with about four to five people you go in there and you say does anyone have a a story about a ghost and almost exclusively you will get you will get somebody that says oh I have a ghost story it's really weird here you go here's mine here here's my ghost story uh it's it's a secondhand story it's from my it's from my uh it's from my mom my mom was downstairs doing some laundry and she saw a kid run by making some sounds and she called my name and then she realized that she dropped me off this is stupid by the way this is a deeply stupid statement uh anyways she she she realized she dropped me off and that there were no kids in the house she got so freaked out about that she called the realtor the realtor looked into it turns out a kid was murdered in that exact spot where my mom was at typically you have to you have to disclose that kind of stuff so it's like is that weird I don't know my mom was so freaked out by it that she did that so it's like is that weird I don't know is that a real ghost I don't know but why are there ghost stories right why are there ghost stories it's just weird kids have been murdered in most spots that is also an insane statement to make but why male models this is so made up it's not made up I've had here's here's another story for you um my mom six months before my dad died had a dream that she came home and my dad had chopped each one of our heads open and our brains were exposed and then a tornado came and she took us all downstairs and everybody ran downstairs into like uh the like we haded this we had a tornado shelter and then she looked up and there were my dad was not there just us kids and then the voice of God entered the story and said from here you will rebuild shortly afterwards my dad died the day after my dad died my mom had another dream where my dad came there and said you need to immediately go check the bank account something is wrong turns out that exact bank account which he specifically stated his best friend started stealing money out of it like that day he dies Next Day best friend starts stealing boom so again how does that work out I don't know is it strange I don't know it's just weird okay it's just weird what are dreams why do sometimes people say they see ghosts I don't know ghosts are weird okay life is probably much more complicated than we make it right life is probably my therapists going to hear about it I don't know it's just quirky I love this t i don't it's just a weird tangent anyways I just love that question do you believe in ghost because the the natural answer is no but then like I just just you you meet so many people with compelling ghost stories and so you're just like I say no but but that sounds religious dude you don't even know what that word means and you are deeply religious like the thing is I hate this term because people are so stupid these days they don't even know what the term means the term means what you hold on to you hold on to something you are equally as religious you're using the wrong term at least use the right word people just at least use the right word come on you're using the wrong word altogether religio means to bind yes it was it was to it was to hold on to uh the the general conception of the word religion was to hold on to a rope uh your ship cuz you know back then they had to like go on ships and and and they had to go like travel around and it was horrifying and they'd go and sit on a ship and it'd be all awful and huge waves would come and they'd have to hold on to something it sounds superstitious that would be a much better word there superstitious Superstition is also super weird the the least the least like I can't tell you how many people that I meet that are like atheist but they will like ardently knock on wood and you're just like yo dog that's pretty superstitious why you why you so superstitious right Superstition is super strange everyone is so dumb what do you expect from twitch chatter I don't know anyway superstitious is really I'm just a little stitious I'm just a little stitious superstitious is real weird that stuff is real weird like basketball players will only wear like a certain set of shoes have you have you heard this where like there's like I will only wear this pair of socks cuz it makes it work and you're just like dude that's crazy that's a crazy one right like that's some that's some real superstitious weird stuff right there that's a placebo it doesn't matter it's Superstition right that's that's what that is you crazy I know people that's crazy and ghost say I don't know ghosts are crazy too I don't believe in ghost yet I don't know you know what I mean like I I just don't take things so onedimensional I just don't even know it all kind of freaks me out yeah placebos can work in a mental in a mental state not in like a physical state uh broken anible thank you I guess they can kind of work in a physical state as well for some period of time too um hey thank you uh Trio I appreciate that sorry for the tangent let's go uh the Rob white let's go I personally believe that gos don't exist but weird stuff happen all the time and ghost stories are simply the vernacular for describing odd happening who knows yeah I mean you very well could be right Jay appreciate that a special message for a special day broken anible thank you very much Kio let's go let's go Kio like here's like here's a here's a weird one I can I will know about 30 to 40 seconds I'll know it's not even that about five minutes 4 to five minutes before my wife has a night terar she has them a couple times a week and she doesn't wiggle she doesn't change her breathing I can feel it how weird is that I can feel her anxiety like emanating from her I can feel her nightmare beginning and she's not wiggling she's giving no signs of it at all and I can feel it it's weird I can deeply feel it and I I will wake out of my sleep and I'll break out into a sweat and I can go oh my goodness she's about to do this here we go here we go here we go like I can just feel I can feel the the intensity about to happen it's wild all right well I can't tell like I I can't tell broken anle thank you very much I just know you know it's weird stuff sounds like love sounds like Terror to me can you Waker and prevent it I tried it it turns into a night tear it's a night terar either way it's a night terar either way and sometimes I think that my intensity about her having a night terar will induce her to have a night terar I can't tell sometimes I feel like I can stop it I don't know it's it's strange is she lucid dreaming yeah she kind of has some some sort of like wake dream it's more like waking dreamed she doesn't really remember it this is uh is the cause I might be giving her the night terrs that's what I don't know night terrs are caused by the prime confirmed dude I maybe anyways all right let's keep on going where are we this is the strangest tangent of my lifetime all right where are we at all right detect problems let's let's figure this out catch using catch to replace an error with a default value is a bit of a blunt instrument since it doesn't matter what the eror is correct catch let us capture the value uh the error value and perform additional actions okay very cool okay I can okay so I can see why uh Lewis earlier said that he thinks this is a bit of a foot gun um I can see why the catch right here I guess the state you'd have to kind of maintain some of the state in these moments it's kind of interesting I don't know I'd have to think about this more anyways all right let's trace this through let's trace this through just make it right just make it right a 32 my error 32 if there is an error we just simply return the error okay interesting so that's why it returns this so we actually didn't do anything with that uh let's see just make it right calls fix too big uh cannot fix any errors calls fix two small fixes two big errors calls detect problem fixes two small errors okay fix too small oh dear we're missing a lot here okay okay I see what happens here okay so I go like this I'd go catch and I could get the err and then I would do something like this a detect problem we have this one too small if or oh gosh I I really wish they could get rid of that I really I really wish that was gone wait hold on if R equals uh my number error uh too small then we need to do something let's see if too small we should return 10 okay oh I hate automatic formatting I'm going to have to turn that off immediately I hate automatic formatting please don't ever do that that's a terrible default setting because I I'm like a chronic saver so I save and then it does that then I have to undo it and it's just like okay okay okay okay that makes sense I liked that he's learning Zig Hallelujah he's learning Zig I'm just trying to working through that air is a weird abbreviation Choice why is error why is error cuz it's an error how's that a weird abbreviation choice I mean I could go with I guess you're right I could go with like e what would what what would be a better one two air is human what what would be a better choice here I'm so confused now this is my air better let's call it success there we go successfully failed does that does that feel better more positive for your Zoomer ass okay makes you feel good that your code even your errors are nice oh that makes me feel so much better about myself I was still successful um anyways is not successful no you wouldn't do that that's that's way too that's way too damaging for someone's psyche you can't be naming things like that uh Z has a handy try shortcut for this common error handling okay lithium we're over here positive affirmation you're good enough and Steward SMY um hey thank you very much lithium let's go I appreciate that put it back to air nope it's successfully failed now okay lithium I appreciate that thank you lithium uh you do not use telescope dude how do you think I've been getting to each one of I'm I've been telescoping this whole time what are you talking about Chad chat is wild Chad you wild all right what's the what's the issue here okay so Chad you wild Chad you wild hey Peak nuff uh I sub to watch vods I always love it hey see you buddy I appreciate that thank you for the 20 gifted Subs again in broken anible thank you for the gifted sub let's go wild and out out here okay so we have add five this function needs to return any error which might come back from detect please try okay yes because this is a this is a this is a union type and you can't do that so that's probably why it's breaking right yeah invalid operation for eror Union okay so we got that one so instead of doing like a catch I think this is what they what they mean by this is that you'd go catch return uh return e instead you can just go try right so this would be the equivalent of that that's the equivalent of a question mark in Rust right do I like this better in some sense I do like this type of uh syntax better I'm always more of a fan of keywords because I can see keywords like without like without focusing um but I do like this I do like things in post fixed because then I can do something like that right which is much nicer so yes try just bubbles it up one level that's all it does try just bubbles it up that's why we return this error right here the question mark I I I'm on the fence still about me loving the question mark you can use catch and post fix yeah uh rust has a triy macro it did so addict uh the tri macro was a was replaced with the question mark the tri macro was literally like the first the first iteration of the question mark operator right so all right we're on 26 let's do 26 okay great news we let's see now we know enough to understand a real Hello World program in Zig one that uses the system standard out resources which can fail okay uh take note this is main definition now returns bang void rather than just void since there is no specific air type this means Zig will infer the err type this is appropriate in the case of main because let's see but we can make a function harder let's see but can make a function harder function pointers or even impossible to work with recursion in some situations you can find more information right here okay interesting so inferred air sets could be something we look into right now air sets I I feel like I know enough about sors now to really get going I'm actually really excited about trying out Zig with the problem like I'm very excited about solving this problem with Zig and comparing it to go right I I think this is going to be good never mind appreciate that twitch Prime and bow Mystique I appreciate that tier one and uh inspiris I appreciate that tier one so I'm going to be giving you guys a good video about how it feels to use Zig in I guess in my in my head so more than one error so that's that's what I don't understand is how do you return different types of Errors you might have to like upscale your error into a new error you you know what is your favorite language to use I don't know if I have a favorite language anymore it used to be rust but I just got so annoyed with certain parts of rust and also the foundation that I just decided that I I got really tired of the community I after faster than lime called me a racist that that was really the last time I think I I really loved rust and so I was just like I can't do this anymore these these the community sometimes is so annoying there's so many good community members and then there's so many annoying ones and I just want a normal one I just want a normal like why can't we just have just a group of normal people like why is that why is that difficult crabs is bugs not people yeah rust rust can just be rust can be obtusely difficult in some in some parts right R Russ can just be really just just super annoying yeah you need to wrap your errors into higher order error enems exactly lowle learn that's what I figured would happen um uh normal people don't want to manage a programming language that's also Fair that's also fair fair statement you already are kind of strange person to be wanting to to like full-time do an a language right uh let's see all right we would get a writer from the standard out so we can print okay so we got a standard out get standard out unlike standard out print a standard out writer can fail with an error we don't care what the error is we want to be able to pass it up as a return value of main okay so that means the standard out print probably returns an error yeah so I just I just hit it with a try or I guess I could also return right I could do either or I'm pretty sure I can just return as well yeah so I can do that or I can just hit it with a try yeah okay so I can do either or the reason why I can return it is because its return type is aor void which matches my signature right here so you can return a void so okay that makes sense I like that uh 27 uh I never said only go for a year that's like literally impossible in any programming language that's you can you I literally made a front end to my project that I'm working on I had to use typ I had to use yava script uh you can assign some code to run after a block of code exits by deferring it with a defer statement defer run later run now okay so defers I like defers I think defers are good uh in the the example above run later will run the block uh uh when the block is finished okay so it runs on a block level that's cool not on a function level but on a block level I like that that's interesting so the code above will run in the following order run now run later without changing anything else please add the first statement to the code in our program to okay so on just just so I understand I just wanted to make sure that this operates the way I think it does Okay cool so it is on a block level as opposed to a function level so it is different that is different is defer uh just Ray with uh but simpler sort of mattz is nice and so we are nice that's funny uh minus Swan minus Swan I like that minus Swan that's a cool yeah a scope level is pretty cool I like the idea of scope level I think I could I could really get into scope level stuff all right 28 let's see now that you know how defer Works let's do something more interesting okay print animals all right this function is supposed to print an animal name in parenthesis like goat but somehow we need to print uh the end parentheses you know this is this is kind of interesting to use this defer is kind of interesting little concept to use right here another common problem is a block uh is a block of code that could exit in multiple places due to an error but that needs to do something before it exits typically to clean up after itself an air defair an air defer is a defer that only runs if the block exits with an air oh interesting I'm not sure I feel about this one either I mean defer is already kind of like a hidden control flow okay please make this a failed message only print on make number okay so you can do uh air defer so if we get an air and we return with an air we get that cool okay so it only fails right here defer is uh good for cleanup defer is very good for cleanup air defer is useful for clean up and allocations in case of an air yeah air defer seems nice I've definitely written not very nice SL obvious code to do things uh in a defer but only if error happened yeah error defer is uh super useful with allocators okay yeah I could see it being super useful for allocators because I would imagine that if you I would imagine that if you allocate something and then you have to allocate another thing and then you have to allocate another thing and like this is the thing that you want to return back to the person but for whatever reason you like error right here you can go back and just clean up that guy so I to me that that I mean it does make sense that there's like a a way in which you want to do this i' I'd argue that defer a defur is more implicit than hidden control flow I I would argue it's more explicit than hidden control flow because there is no hidden it's not hidden you explicitly Define it defer SL ER defer is basically go-to so is an if statement so is a while loop so is break so is continue I mean they're they're all th those are all go-tos we just have name function calls are go-tos yeah that's what I meant like finally finally exists in many language finally is another one of these this is like a finally in some sense but it's not a finally defer is more like a finally defer would be more like a finally air defer is like catch finally only on catch which is it's it's very interesting I can see why it's very good for allocation if you have to do like a multi-part allocation and so I like that I mean I I I think that's that's totally valid what if you air defer errors do you air air defer you air defer air you air defer air a to for R I wish it had a ye command uh skip Trace thank you for that woot hoot all right all right let's go to 30 the switch statement lets you match the possible values of an expression and perform a different action for each uh players one two else okay there's a default statement this is equivalent of that okay import this thing uh for Lang C switch on this one we don't need everything in between print these things the switch statement must be exhaustive oh okay so if you want it to be exhaustive you need an else right so that means I'd want to do something like I think that's right right yeah okay cool okay that's cool that they require switch statements to be exhaustive I like like this idea I like the idea of uh of of of exhaustive switch statements I'm I'm I'm happy with that I think this is a good I think it's a good place yeah I was doing I was doing Zig uh I was supposed to do Zig uh Saturday learning but today's Track event for my kids got cancelled so since it got canceled I have the dayree since I have the day free I'm going to I'm going to stream so sorry yeah it's extremely nice doing refactoring I agree uh well it's it's it's extremely nice doing refactoring unless if you have an else statement El's are like I get the point of them but they can be very um annoying right I think J below langang you can uh you can use the compiler directives to specify whether you wanted uh the switch sa to be exhaustive or not I I don't know if that really matters to me because if you don't have it as exhaustive you'll you'll end up having an error or if you have it as enforced exhaust if you always have an else and then you have an air if things change I don't know it's to me it's like I I'm not sure if you really you buy a lot with that you know unreachable yeah you can do it you can hit it with an unreachable or whatever it's called boom unreachable screw that all right anyways okay well I like this this was a good initial exploration of Zig I'm going to use the bathroom and I'm going to go check in on the kiddos make sure everything's okay
Info
Channel: TheVimeagen
Views: 82,347
Rating: undefined out of 5
Keywords: software engineering, software, vim, bash, rust, vtuber, programming, programming live, live coding, coding, developer, developing, web dev, web live coding, rustlang, golang, typescript, javascript
Id: OPuztQfM3Fg
Channel Id: undefined
Length: 90min 0sec (5400 seconds)
Published: Sun May 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.