Using Zig | My Initial Thoughts on Ziglang

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I get asked about Zig all the time what are my thoughts on Zig and I finally just took the dive and I'm finding out about Zig I've been programming it now for quite a few hours really getting into it kind of enjoying it there's a lot of things about Zig that I really like and there's a lot of things about Zig I don't necessarily like and so I'd kind of like to share my experience with Zig with you and then kind of give what do I think the future of Zig looks like I don't know what these hand gestures mean okay it's just things I do I don't know what I'm doing when I talk alright so a couple cool things about Zig first off it has tagged unions if you're not familiar with tagged unions you can check out rust enums they're the same thing there's not really an equivalent of this in typescript you can like force it to happen but it totally sucks uh the second thing I really like about Zig is that it has this right here so this bang effectively means this function returns an error and it's actually inferring what type of error it will be returned I can specify that specifically and say hey it returns an error and it's of type my air you also don't have to do that which can lead to a lot of conveniences and you can see why later which is or not even later you can see why right now look at this so if I call a function that has the the ability to error you're gonna see you're gonna have to use the word try to get the value out and not just have this value error Union and so to me this is super cool because when you use try it doesn't throw the air somewhere all it does is returns it from the function I'm calling so if this thing errors instead of just throwing the error it says hey I'm just going to return it from your current function so main will just exit with the error from this if we call it with the value of 420. so if I do that go here run it you're going to see right here I got an access denied that's the error we got all right pretty cool right like I like that I love a language that has errors as values I think that that is just a requirement for any new languages I think it's one of the biggest disasters of all time throwing errors is horrible you don't know who catches it the control flow is super hard it's really hard to keep state in a good place when you could just end up anywhere instead you know exactly where you're going You're Going one function up if you oopsie Daisy and at some point you handle the errors where you want to handle errors at and so just makes you handle errors in a specific place I think it just just much better developer ergonomics another thing is this right here this little question mark this means what I'm returning could be null and that means it's kind of like a part of the type system so if I want to access something that could be null I have to go if item and then I get the inner value out the non-null item this is called an optional super fantastic love this idea because it really just prevents an entire host of problems you always have to specify things that could be null as null and then when you work with them you always have to unwrap them in this kind of case and there's kind of like some forced unwrapping you could do so I could just go like let through Oh wrong language here uh constfu equals item this but if oh item if I I were to pass in something that could be null this would end up in a really bad place right it would end up with me exploding so if I go Foo f i uh Foo there we go look how beautiful that is and do that it's gonna probably tell me I'm gonna air there we go look at that boom panicked you can't you can't use a question mark on on an all item so pretty cool stuff I really like that I really like this experience because I think it's the right experience at a language level one last thing that's super cool about zek I think this is one of the just the most revolutionary features which is everyone hates macros we can all agree macros generally just are hard to work with even in a good language with macros like rust they're still hard to work with they're hard to create in a bad language like preprocessor macro type things with C or C plus plus they're just horrifying but Zig is like the best of all worlds this is effectively a macro it's a compile time item so I'm creating a stack and you pass in the type and it passes you back out the type specified to that generic so it's kind of like generics it's kind of like a macro and how I use it all the way down here is like hey I want to create a stack of type int and there we go I've just created it so at compile time since this thing is only used once it literally generates the code for an INT stack that's like super cool it's very very easy to understand what's happening here if you're Vaguely Familiar with Zig and the compile time semantics are just wonderful I can see myself totally loving this feature about Zig alright so now on to some things I don't like about Zig or things I've never really liked uh the tooling is kind of just you know it's it's just it's not the best it's really not the best they're just starting to get a package manager in the upcoming version which means there's just a lot of problems with including other people's code still and you know I I just can't imagine any modern language not having a package manager at this point it's just like a requirement second I find that the LSP is kind of trash right now and I don't know how long it's gonna take for it to become something amazing because LSP these are really hard to keep them amazing especially as the language evolves watch this here's here's a really simple version I'm going to take item and I'm going to just rename it to item three oopsies uh I already have something called item three I'm gonna call Item 33 it just like it literally it's like I can't do that if I quit Vim relaunch it go down here go to this likes go back down here and try again let's just rename this one and call it this is just like I I I don't know what you're talking about I don't know what you're talking about and sometimes when you do it I think it just happened right there my LSP just crashed the actual sub process launched just crashed and yeah they'll fix this problem this problem will go away right away but this is kind of like a larger issue is that the language itself still has a lot of rough edges around the tools but more more than that where can I even use Zig what is Zig good for well you know a lot of the string handling new utilities they're okay so for me to use it as a CLI tool I don't know if I'm gonna use it as a CLI tool honestly like I think I might rather use rust or typescript I don't know if I want to use Zig there where I see a really cool part for it is that Legacy C C plus plus code bases could be amazing to use zinc you could upgrade it start using something better and you can still kind of really interact and be pretty smooth with the build system but you're using Zig you're using something that's just easier to maintain in my personal opinion and a bit more expressive and just just nicer overall okay I like it better than C plus plus okay I like it a lot better come on but again this always gets to my same thing which is what is the purpose what is the purpose of Zig I failed to see Zig taking a large stage in the language area like I think JavaScript typescript has obviously taken one of the biggest stages ever I think go clearly has a stage that is good even though the language is not that convenient Java obviously has a huge historical stage that's still standing on and rust is kind of developing its own now is there room for zig no I don't know what space it's gonna really take a hold of other than Legacy systems and that's kind of where I struggle is what is it going to be now obviously I need to use it more I'm going to keep on going if you don't know I'm building an interpreter on Twitch right now with Zig and rust and typescript and kind of comparing the developer experience of it all and right now Zig is nicer to work with than rust but this is also a really small problem but in general rust is really nice to work with with like cli's and stuff so I I don't know I don't know if there's one more thing I could say about Zig which is that new users to the language will quickly ramp up that is a huge positive which is what is your 0 to 60. in JavaScript your 0 to 30 is pretty fast your 30 to 60 can get all wonky because of all the little sharp edges the build systems the integration the all this is a build one without them like all the configuration environment stuff just makes it super hard go the 0-60 is like a day right it is pretty easy to not know anything about go and become productive and go right away uh Java I think the zero to one is pretty difficult you gotta like learn Maven and Gradle and I don't know Gradle these nuts nobody knows what's happening uh with rust the zero to one is super simple right cargo and knit the 1 to 60 takes a half of a year right it is a very hard language to get going but once you get going it's really awesome and Russ really struggles with this whole concept of like if it's a black box problem a problem you just know the inputs and the outputs super great but anything that's really exploratory it seems to suffer a lot harder as far as speed goes but Zig the 0-60 is great right it takes a couple days and you're doing fantastic and so I do see that being a win there I do I really do see Zig having a win there so we'll see what the future holds I think the next couple years are really going to determine how big zig's gonna get hey guess what the name is the primagen
Info
Channel: ThePrimeagen
Views: 129,801
Rating: undefined out of 5
Keywords: software, vim, programming, javascript, typescript, software engineering, web developing, web developer, software developer, developer, cpp, programmer humor, humor, reactjs, js, ecmascript, tc39, Netflix, Engineering, Engineer, Facebook, Amazon, Interviews, Software Interviews, vimrc, neovim, spacevim, vim c++, vim editor, text editor, vscode, vscode vim, vim plugins, autocomplete, vim autocomplete, nodejs, twitch, developer productivity, spacemacs, algorithms, datastructures, Data Structures, python, bash
Id: VU1h-h9doS8
Channel Id: undefined
Length: 8min 56sec (536 seconds)
Published: Tue May 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.