Using Zig | My Initial Thoughts on Ziglang

  Рет қаралды 255,926

ThePrimeagen

ThePrimeagen

11 ай бұрын

All of the learnings were done on twitch where i build a stack data structure (planning on doing more) and going through and building an interpreter. We are just finishing up the extended lexer grammar and then we are on to the parser (at the time of this comment)!
Twitch
Everything is built live on twitch
Twitch : bit.ly/3xhFO3E
Discord: discord.gg/ThePrimeagen
Spotify DevHour: open.spotify.com/show/4MLaDrQ...
Editor
All my videos are edited by Flip. Give him a follow! / flipmediaprod
Join this channel to get access to perks:
/ @theprimeagen
Links
Linode: linode.com/prime
/ discord
Twitch: / theprimeagen
Insta: / theprimeagen
Twitter: / theprimeagen
VimRC & i3: github.com/ThePrimeagen/.dotf...
Keyboard 15% off bit.ly/Prime360 USE CODE PRIME360
#coding #neovim #typescript #programming #vim #softwareengineering #codinglife #webdesign #webdevelopment #webdev #javascript #rustlang #rust #twitch #twitchstreamer #programmerhumor #codinghumor #software #softwareengineer #softwaredeveloper #softwaredevelopment

Пікірлер: 597
@ThePrimeagen
@ThePrimeagen 11 ай бұрын
Real Talk, no idea how i accidentally uploaded with 720p. Deal with it. Sorry, not sorry, subscribe to make it 1080p
@nomoredarts8918
@nomoredarts8918 11 ай бұрын
Will you upload Roc video in 4K?
@mateator25
@mateator25 11 ай бұрын
im a phone user so i couldnt even tell
@darkfoxwillie
@darkfoxwillie 11 ай бұрын
i miss you making videos on the main channel, the second channel is awesome but sometimes I like to see some code and benchmarks :3
@GLAJMAN
@GLAJMAN 11 ай бұрын
wth?! Why 720p, explain yourself!
@allhasread
@allhasread 11 ай бұрын
I can only watch at 144p anyway :p
@scottiedoesno
@scottiedoesno 11 ай бұрын
It's so useful seeing your methodology around checking out a new language and I always learn something new about it each time you do it. Thanks for being willing to learn in public and share it with the community!
@AlwaysStaringSkyward
@AlwaysStaringSkyward 11 ай бұрын
If Zig became the de-facto language for embedded instead of the 3,457 slight variations of C that would be no bad thing...
@DAB009
@DAB009 11 ай бұрын
I hope micro zig does a great job at this. It will be revolutionary.
@adriankal
@adriankal 11 ай бұрын
Why not rust?
@NickSteffen
@NickSteffen 11 ай бұрын
@@DAB009 Not sure if this is sarcasm, but it’s a bit ironic to have someone complain about C because it has too many variants, and then propose to replace it by creating a variant of a different language. I think the problem is that for embedded you are always going to have language features that just don’t work for certain hardware specs so your always gonna have a ton of variants since each of the different manufacturers makes a custom compiler for their platform
@ryshask
@ryshask 11 ай бұрын
Just learn C well... You're gaining nothing by learning languages de jour.. there are mem safe allocators in C... Use them for large projects.
@NickSteffen
@NickSteffen 11 ай бұрын
@@ryshask The problem is that there shouldn’t be “wrong” allocators. (And the many other wrong versions of things that c allows for (like the nonsafe string operations)) Training new devs is too time consuming in C and even experienced devs make too many mistakes and for that reason it will die, it will be a really slow death but it will be a death. C was the first language i learned and I have years of experience with it and I dislike it all the more because of it. It’s like writing with quill because if used right it saves a drop of ink. Also things like mem safe allocators tend to be excluded from embedded variants of c. Which is one of the problems with just creating silly new versions of things instead of actually fixing the language.
@ThatJay283
@ThatJay283 9 күн бұрын
yeah zig has definitely nailed its compile time stuff. like it seems to be the perfect constexpr/template/macro alternative
@dzisonline
@dzisonline 11 ай бұрын
I like the 0-60 analogy. Makes sense.
@GMDeatHSoul
@GMDeatHSoul 11 ай бұрын
What does he mean by 0-30 and 30-60? What's that analogy? Is it about your productivity, or % of "knowledge" about the language?
@dzisonline
@dzisonline 11 ай бұрын
@@GMDeatHSoul 0-60 is a car speed test to see how fast a car accelerates. He was comparing it to "getting up to speed" in a programming language. With Java example 0-1 is difficult because there's a lot to learn to begin but with Javascript 0-30 is pretty easy but 30-60 is pretty hard b/c of the ecosystem.
@GMDeatHSoul
@GMDeatHSoul 11 ай бұрын
@@dzisonline Oh thank you very much for explaining this, now I get it :)
@alexander_nunezf
@alexander_nunezf 2 ай бұрын
Zig makes me recall Ziggy Marley...nice : 🌿
@DNA912
@DNA912 11 ай бұрын
0-1 and 0-60 analogy is the best analogy I ever heard on language difficulty.
@alexandersemionov5790
@alexandersemionov5790 11 ай бұрын
Zig for typescript developers coming up !!!!
@DisFunctor
@DisFunctor 11 ай бұрын
Errors as values is awesome. I fell in love with programming again when I learned Scala with ZIO strongly encourages you to do that (well, more generally, it lets you do "programs as values"). In the past I've had a hard time articulating to other people why it's such a game-changer... Either way, I'm 100% definitely going to be checking Zig out now!
@xavhow
@xavhow 8 ай бұрын
Yes, there’s room for Zig. I started learning Rust a while back and find it hard to grasp. Then tried Zig and felt right at home (referred from Bun’s Author). I know Zig isn’t on par with Rust’s memory safety lbut it’s ok! That’s the trade off I’m willing to make. I want something non-gc and am able to be productive in it.
@madskaddie
@madskaddie 3 ай бұрын
How did you not commented the allocator APIs? They are another great idea, in particular if you are a performance guy :) Yes, it can be a burden to keep passing them, but everything is visible: Now the answer to "does this function i'm calling allocates memory?" is in the function signature and the allocation strategy naturally configurable
@aazzrwadrf
@aazzrwadrf 10 ай бұрын
this quick overview was super helpful to me. thanks!
@Martinit0
@Martinit0 11 ай бұрын
In case anyone wondered what "LSP" is - it's a Language Server Protocol - a way for an editor to know about the semantics of a programming language so the editor can offer advanced features, like renaming (all occurrences) of a variable. en.wikipedia.org/wiki/Language_Server_Protocol
@chasewilltin8567
@chasewilltin8567 5 ай бұрын
thanks
@batboy49
@batboy49 11 ай бұрын
Wow pretty much what I thought about all of the languages you mentioned ..I really like your 0 to 60 analogy
@yonderalt2662
@yonderalt2662 9 ай бұрын
Errors as values is a C-like thing to do, I love C!
@DuarteMolha
@DuarteMolha 6 ай бұрын
Such a cryptic language for reading. I know my expectations is biased because i mostly work on python. But damn that is dificult to read
@danielsan901998
@danielsan901998 11 ай бұрын
no mention of the build system? For me that's one of the advantages is not having to use Make and CMake and instead using zig to compile C programs.
@michaelthompson7217
@michaelthompson7217 11 ай бұрын
yeah if zig in an alternative universe was JUST a build system it would probably be popular too
@simonfarre4907
@simonfarre4907 11 ай бұрын
So what's your problem with CMake? I find Zig's so called "build system" terrible. It's in a terrible state probably because of the version, but claiming it's better than CMake, I wonder why anybody who has programmed in C++ more than 2 days, would think that.
@dominiklukacs7677
@dominiklukacs7677 11 ай бұрын
To me it just always seemed like I was spending an unnecessary amount of time on trying to build anything in C++. When I first learned the language I thought “okay, bit difficult but I’ll get better with time”, but I just ended up getting more and more frustrated the more I used it. Something like Rust’s Cargo in comparison is crazy good
@simonfarre4907
@simonfarre4907 11 ай бұрын
@@dominiklukacs7677 I find that pretty strange, to be honest. CMake massively simplifies things. Sure, the ecosystem is terrible since it didn't unify it or it's not part of the standard. But Zig seems _massively_ much worse, especially in the current state it's in. Yes, Cargo is pretty great, for most things. It doesn't come without it's flaws though. Cargo does borrow concepts from CMake though, which is pretty nice, particularly how one can set up workspaces. C++ build time is also *massively* faster than Rust, which I find particularly annoying with Rust.
@Sergeeeek
@Sergeeeek 11 ай бұрын
@@simonfarre4907 how is it worse?
@freakmangd
@freakmangd 11 ай бұрын
i use zig for gamedev instead of rust/c++. its super easy to use preexisting c/c++ gamedev libraries (which there are many) and i feel it lets me be more experimental and prototype quicker than the very strict nature of rust. im hoping for the best but even if its not that successful im still very happy using it :)
@danvilela
@danvilela 11 ай бұрын
Which engine do you use? I might try this
@delphicdescant
@delphicdescant 11 ай бұрын
Same. Zig for gamedev is a dream. I didn't have as pleasant a time using Rust at all. In fact, I got kinda sick of Rust after a while.
@jawad9757
@jawad9757 11 ай бұрын
​@@delphicdescant did you read the rust book beforehand
@delphicdescant
@delphicdescant 11 ай бұрын
@@jawad9757 Well yeah of course, since it's the primary reference material. I spent a few years being excited about rust, but that shiny excitement kinda rusted ngl.
@_matevo
@_matevo 11 ай бұрын
@@delphicdescant Same for me man even the latest problems made me to switch from Rust to C++ back
@gritcrit4385
@gritcrit4385 8 ай бұрын
Special error types seem really nice to use.
@FightinTheGorlax
@FightinTheGorlax 11 ай бұрын
A lot of the features you're listing off are some of my favorites from Dart and a few seem to have even better implementation, def wanna try this out!
@renegadeace1735
@renegadeace1735 7 ай бұрын
Uses 'fn' to as the function keyword, I love it already.
@rockybalboa5055
@rockybalboa5055 11 ай бұрын
As someone primarily using C for side projects, I feel like I could have a much easier time. Gotta try it out some time soon
@mastermati773
@mastermati773 11 ай бұрын
4:05 Templates?
@IanRiley915
@IanRiley915 11 ай бұрын
Hey Prime! Could you see yourself contributing to Zig tooling as part of your content? I’d be really interested in seeing you dive into some of the tools and discussing how to implement them. I recognize that’s a big ask.
@gabrielbeaudin3546
@gabrielbeaudin3546 11 ай бұрын
Zig is amazing for game dev.
@halfgrin
@halfgrin 11 ай бұрын
It's still very much early days for Zig, but what they've been able to accomplish so far is pretty impressive and I'm very much looking forward to seeing how the project develops within the next few years.
@ThePrimeagen
@ThePrimeagen 11 ай бұрын
agreed
@JohnDean-my1dx
@JohnDean-my1dx 11 ай бұрын
What do you mean by 'early days'? It's an 8-year-old language.
@AbuAl7sn1
@AbuAl7sn1 11 ай бұрын
​@@JohnDean-my1dxolder than my brother
@jawad9757
@jawad9757 11 ай бұрын
​@@JohnDean-my1dx relative to other programming languages it is very new
@Leo0718
@Leo0718 11 ай бұрын
@@JohnDean-my1dx When people still regularly program and maintain code bases in production with languages that are 50+ years old. At 8 y.o. your language is still a baby.
@jony1710
@jony1710 Ай бұрын
I've been playing around with writing some stuff using UEFI to learn more about how bootloaders work, and I feel like I spend way too much time futzing with types in Zig at the moment. I'm not an expert but I think I understand the memory layout of C like languages pretty well, but it just takes me a while to get []u8, [*]u8, [*:0]u8 etc. right. I also find the standard library around strings leaves me wanting though I'm sure this will evolve over time. Not having an interfaces equivalent is a pain point for me because things like the std.fmt.format() function is very opaque without them. Overall I think it's conceptually pretty cool as a language (I wish C would add defer) but frustrating to use at the moment. I mostly work in Go, and I just wish Zig had embraced that philosophy a little harder. It's definitely less complex than C++ and I love that, but it's still just a bit too complex for me to choose it over C for this kind of stuff (small hobby projects to learn something new like UEFI)
@109Rage
@109Rage 11 ай бұрын
I think most of the LSP issues you mentioned are fixed by now. It's just that Mason has an outdated version of ZLS in its registry. (technically it's the latest "release", but as with everything in Zig, if you want things to work you need to keep up with nightly releases.)
@GogiTavadze
@GogiTavadze Ай бұрын
So "try" is basically "if err != nil {return err}" from Go?
@gaius_enceladus
@gaius_enceladus Ай бұрын
I'm a newcomer to Zig and I love it! I'm a big fan of the "keep it small" approach and I love that Zig has no header files (unlike C and C++) - I've found that speeds up development a lot. I toyed around with trying Rust but it looks like Rust is going the same way as C++, becoming huge and bloated. Nope, not for me.
@DrIngo1980
@DrIngo1980 11 ай бұрын
Interesting tidbits about zig and your experiences, thanks. Any thoughts about Nim?
@lhpaoletti
@lhpaoletti 8 ай бұрын
Prime, have you ever thought about posting your livestream series on KZbin, specially the programming ones, like the one you mentioned in this video? Because in your Twitch channel I cannot find the livestream videos of said streams.
@prozacgod
@prozacgod 7 ай бұрын
@1:52 - this vaguely reminds me of lua's pcall
@aaroncohen6577
@aaroncohen6577 Ай бұрын
Hi primagen I seem to remember you saying in one of your videos that you are doing a course in Lower level networking. Can you link to that?
@felipediaz2388
@felipediaz2388 11 ай бұрын
Well, one more mouth to feed in my family of technologies. Thanks to ThePrimeagen
@Keras___
@Keras___ 8 ай бұрын
The extremely high compilation time, the lack of certain modern features by default like async, the struggle of integrating with C/C++ code, and certain safety-imposed restrictions are driving me crazy while using Rust. As a fan of the good old C, I think I'll enjoy getting to learn Zig.
@Sergeeeek
@Sergeeeek 11 ай бұрын
It's positioning itself as a C replacement, that's why they made sure transitioning from C/C++ to zig is super smooth with zig cc being a drop-in replacement for cc. Another thing you didn't mention, but I think is super important: they ship the whole compiler as a statically linked executable with full cross compiling for all platforms they support. They even include platform specific headers for Windows, OSX and multiple glibc versions with the compiler, so you don't have to install anything else locally. I'm sure a lot of C/C++ users will switch to zig cc even if they don't care about the language itself simply because of how convenient the build toolchain is.
@ea_naseer
@ea_naseer 11 ай бұрын
should I learn zig or c? I learned C when I was in first year but I had to drop it at the way side to learn other things but zig looks really cool so what do you think?
@Sergeeeek
@Sergeeeek 11 ай бұрын
​@@ea_naseer I've only dabbled with Zig and C. IMO Zig is much better at doing what C does best. But it all depends on your goals. If you just want to learn a low level language for fun, then Zig is very nice. If you want to find a job then C, for sure.
@Sergeeeek
@Sergeeeek 11 ай бұрын
@@ea_naseer Also if you want a stable language that will definitely be around in 20 years then you should also choose C, haha
@NathanHedglin
@NathanHedglin 11 ай бұрын
Exactly. The tool chain is the actual killer feature.
@isodoubIet
@isodoubIet 11 ай бұрын
Zig needs to have destructors before any C++ programmer will take a second look at it.
@nicolaslopeza2251
@nicolaslopeza2251 11 ай бұрын
Maybe besides legacy systems, zig could be used for embedded systems? Rust is becoming stronger in that area, but i think using zig + c is easier for what i've seen and that is a big plus in embedded
@herrpez
@herrpez 11 ай бұрын
Has anyone else noticed that this man says "pecause"?
@antoninperonnet6138
@antoninperonnet6138 11 ай бұрын
The way you create implementations by passing a type as an argument is the same idea as "functors" in ocaml Really cool stuff !
@rogeliocodes894
@rogeliocodes894 11 ай бұрын
Pretty cool of you to try this. I'm curious as to comparisons of Go, Rust, and Zig.
@sadhlife
@sadhlife 11 ай бұрын
use rust if you want a fast program with no other special requirements use zig if you want a lot of lower level control, like if you're writing code close to the hardware for example. don't use go. (well, unless your team isn't familiar with the other 2 languages, go can make sense)
@diadetediotedio6918
@diadetediotedio6918 11 ай бұрын
​@@sadhlife I think these conditions are a bit confusing, why wouldn't you use Rust at a low-level with high hardware control if Rust literally provides many kinds of code security and the like when we're at that level? And it's not me speaking, Asahi Lina has already pointed out the benefits of using the language to develop the Apple M1/M2 GPU drivers for example.
@sadhlife
@sadhlife 11 ай бұрын
@@diadetediotedio6918 there's always a compromise the higher level a language is in general. Sure, doing things like raw pointers and a custom allocator for specific use cases is possible in rust, but it's just way harder to do than it would be in zig or C. also, when you use safe rust, you are giving away some level of control over the hardware. for example, using rust for embedded systems is much harder yet, whereas using c++ is pretty much trivial these days.
@Sergeeeek
@Sergeeeek 11 ай бұрын
@@diadetediotedio6918 isn't Rust kinda hard to use when you need to manage memory manually? std assumes that you just want to malloc and free everywhere like in C++.
@NathanHedglin
@NathanHedglin 11 ай бұрын
Go is just a GC'ed language missing 90% of all the useful features. Rust = blue haired hippy that wants safety despite never getting any action Zig = basement dweller that can't C.
@CallousCoder
@CallousCoder 11 ай бұрын
I see Zig replacing newly build C/C++ applications truly on systems level. Think micro controllers for example operating systems that need to be lightweight. You just develop quicker in Zig and since you’ll need to disable std anyways then I much rather use Zig.
@airbus5717
@airbus5717 11 ай бұрын
u can also use alot of std in microcontroller level
@CallousCoder
@CallousCoder 11 ай бұрын
@@airbus5717 I know you can but you don’t want to in a small memory microcontroller the std functions are relatively large.
@dagoberttrump9290
@dagoberttrump9290 11 ай бұрын
​@@CallousCoder i don't think you know what you're talking about. What do you mean by "std funcs are large"? Do you mean the cache overhead is too big? The runtime overhead? Dynamic allocation? Do you know about constexpr, polymorphic allocators? You should look into it. C code is ugly tbh
@CallousCoder
@CallousCoder 11 ай бұрын
@@dagoberttrump9290 the binary of rust gets very large when using std functions. 150-200K (after forcefully stripping even) which is too big for most AVR 8 bit controllers that have 32K storage and 2K RAM. Hence you disable std otherwise you can’t really do something useful. The avr-rust project also religious disables std. And frankly I don’t like their arduino_hal class, it’s too abstracted from the AVR interface imo. And C code is wonderfully clean especially for embedded devices. And Zig elevates that even further but I have not seen AVR support yet for Zig last time I checked. But Rust simply didn’t leave enough space to do something really useful on the tiny AVRs when I used certain std functions. Zig will be awesome because you cab effortlessly use the existing clever hardware libraries that AVR has without too much hassle. Best of both worlds.
@dagoberttrump9290
@dagoberttrump9290 11 ай бұрын
@@CallousCoder i think we're talking different things. I was thinking the std library of c++. I heard that rust support for embedded is still lacking, also in regards to pointer arithmetic.
@BrainySmurf77
@BrainySmurf77 11 ай бұрын
Honestly, Zig feels like a better (or at least, as good) inclusion in the Linux kernel than Rust. Think about it - Zig can compile C code natively, bring its own libc, and cross-compile for any hardware. Replace GCC with Zig and bam, you can now add kernel drivers and such with far less footguns. Seems like a win to me.
@SimonBuchanNz
@SimonBuchanNz 11 ай бұрын
Too early, and the safety argument is a lot weaker. But overall, I think Linux might let a few of these new systems language cook in the edges (disabled by default modules, new drivers etc) and see how it works out in practice.
@Luxalpa
@Luxalpa 11 ай бұрын
The borrow checker was the primary reason Rust went into the linux kernel (Rust was originally invented as a solution to memory issues in the linux kernel, with the original purpose of being just an extension to C), so I don't think that Zig would help.
@TimSavage-drummer
@TimSavage-drummer Ай бұрын
Just giving zig a good go right now, and 10 months later I have some of the same issues. The language is nice with some great features, comptime is fantasitc and less frustrating than rust. But some of the tooling just isn't quite there and the docs are very "java-esc".
@bobweiram6321
@bobweiram6321 9 ай бұрын
Why do you review Ada and show what a real alternative to C offers?
@lyzhng
@lyzhng 11 ай бұрын
Would like to see a video on Elixir! 🙂
@icylace
@icylace 11 ай бұрын
I've been using Zig for making WebAssembly and I like it a lot.
@ayyhaha9832
@ayyhaha9832 11 ай бұрын
I’ve been messing around with zig and rust (all because of prime) and honestly I like zig way more, but I did get stuck for hours trying to serialise a struct to json so maybe it’ll be the one in the future lol idk
@qwertgfhxc
@qwertgfhxc 7 ай бұрын
Can you or anybody in the comments recommend one or multiple good error handling patterns?
@sharokhkeshawarz2122
@sharokhkeshawarz2122 11 ай бұрын
this was the video that i was waiting for!
@segeus
@segeus 11 ай бұрын
Who is on background in your IDE?))
@ivansky1027
@ivansky1027 7 ай бұрын
gradle deez nutz I can feel it lmao
@Swampdragon102
@Swampdragon102 11 ай бұрын
Zig is extremely powerful in the "very constrained resources" environment. You want to keep exact track of your resources? Allocations, performance, minimal numbers of bits used. That's where Zig is the strongest, because it can do it all while still being really maintainable.
@bigbodge
@bigbodge 11 ай бұрын
I've seen Zig getting pretty big in game dev
@ThePrimeagen
@ThePrimeagen 11 ай бұрын
this isn't surprising now that you say it. it does seem like a natural place for it. especially with ECS, i could see custom allocators around that
@bigbodge
@bigbodge 11 ай бұрын
@@ThePrimeagen Of course its still quite new so theres not a lot of tooling specifically built around it (to my knowledge theres Mach, a zig game engine in very early stages, and the obligatory raylib bindings), but I guess with that C interop it doesnt really need it in the same way other languages would
@Gorgutzdaboss
@Gorgutzdaboss 11 ай бұрын
@@bigbodge I'm currently working through the vulkan tutorial in Zig and that C interop is chef kiss.
@klmcwhirter
@klmcwhirter 4 ай бұрын
Try building a wasm component or build chain in zig. You WILL get it. Thanks for the vid.
@acebesmonte
@acebesmonte 11 ай бұрын
meanwhile at carbon-lang: Potential 2024 goals: ship a working 0.1 language for evaluation
@TimUckun
@TimUckun 11 ай бұрын
Have you looked at crystal? Really nice enums, super nice macro system. Overall a very pleasant language.
@kristun216
@kristun216 11 ай бұрын
Blazigly fast
@marcs9451
@marcs9451 11 ай бұрын
I love when Andrew Kelley says it's ziggin time and them proceeds to zigs all over the place
@256k_
@256k_ 11 ай бұрын
i see it definitely taking space in the audio/DSP ecosystem which is dominated by C++ right now
@silverhairs
@silverhairs 11 ай бұрын
Oh look, Prime remembered that he has a primary channel
@s1dev
@s1dev 7 ай бұрын
8:10 100% on java! god know's what all is there, I recently tried to make some chances for a friends codebase, ykw it's was a lot harder than anticipated.
@gittawat6986
@gittawat6986 11 ай бұрын
the zig lsp from mason package is still 0.10 , you should build the zls-git from src and manually setup with nvim-lsp instead
@J-Kimble
@J-Kimble 11 ай бұрын
Looks great for embedded, at least at first glance
@fabbritechnology
@fabbritechnology 11 ай бұрын
Glad to see errors as values.. after some dark years of "exceptions are great" and me being anti-exception. I like to say they turn a linear problem (which errors occur in a block) into a geometric one (which errors occur in a block and all of the blocks that are called by it).
@Felipe-bi3mk
@Felipe-bi3mk 10 ай бұрын
isnt it Exceptions without try catch block after all?
@gonzajuarez4918
@gonzajuarez4918 10 ай бұрын
lisp macros are cool. scheme macros are great. racket macros are better
@hankertric
@hankertric 11 ай бұрын
Awesome!
@jdconradie3486
@jdconradie3486 9 ай бұрын
Are you DrDisRespect in your free time?
@VojtaJavora
@VojtaJavora 11 ай бұрын
It's so easy to create a UEFI application in zig. It's all already there.
@JohnCostanzo
@JohnCostanzo 11 ай бұрын
Dam I want that background for zoom, lol
@FascistTrex
@FascistTrex 10 ай бұрын
We have a fellow Zigger hope you like the programming lan
@kevindelnoye9641
@kevindelnoye9641 11 ай бұрын
Throwing exceptions is not meant for control flow. When something unexpected/unlikely happens like out of memory it allows for a mechanism to recover from failure or log the failure. So for example checking if a file exists should be done with error values because you expect there is a reasonable chance of it happening
@ccgarciab
@ccgarciab 11 ай бұрын
This is not how exceptions are used in, say, Java or JS.
@Jmcgee1125
@Jmcgee1125 11 ай бұрын
Except that's not how they do that. Languages focusing on throwing (e.g. Python) tend to prefer throwing exceptions and expecting you to catch them instead of relying on return values. Sure, I can `if not os.path.exists(file): return False` before I open, but then I still have write code to catch the exception in case the file gets deleted in between the check and open. And it's not as if errors like out of memory can't be concisely handled inline. `char* x = malloc(10); if (!x) { return false; }`
@kevindelnoye9641
@kevindelnoye9641 11 ай бұрын
@@Jmcgee1125 python in my experience is kinda 50/50 with checking before or handling exceptions. Because of the dynamic nature of python there is no performance penalty or boilerplate for exceptions. The c example is correct and that is why c is so explicit and verbose when compared to c++ where memory allocation happens in the constructor of a class. People often don't do checks in c, for example when is the last time you checked the return value of printf?
@Jmcgee1125
@Jmcgee1125 11 ай бұрын
​@@kevindelnoye9641 When is the last time you had to? Printing to the terminal, in my opinion, is a "best effort" endeavor - if the user has broken our stdout, that's their fault and we don't need to take special care. Printing to something where robustness matters is when I'd worry about checking the value (e.g. writing to a socket or nonblock fd). Realistically, what would you do on error? Retrying is a good way to busyloop, your best bet is probably to just ignore it. Not checking return values on functions whose error cases are meaningful is a different case altogether. That is poor programming practice, simple as. My distaste for try/catch doesn't come from performance penalties, it comes from readability. Python is actually one of the weakest offenders in this regard, because of how they scope try/except inline with the function rather than as its own block (e.g. Java). That allows you to write code more akin to C handling, though it can be a little weird and still offers the ability to make wacky control flows.
@kevindelnoye9641
@kevindelnoye9641 11 ай бұрын
@@Jmcgee1125 never had to check printf. Was meant as an example that it is easy to forget error return value checking in c. I totally agree with what you are saying, the only place where try catch does add value is at the start of the program to catch unexpected errors deeper in the call stack and throwing exceptions should be done sparingly.
@SnackLive
@SnackLive 11 ай бұрын
i see Zig as a replacement of C but in a way that isn't aggressive about it.
@TechBuddy_
@TechBuddy_ 11 ай бұрын
Hey prime I usually hate these questions but let's say zig's tooling was much better with a solid package manager ( with good packages ) and the LSP was as good as rust would you pick zig over rust ?
@BosonCollider
@BosonCollider 9 ай бұрын
I think in that case it would still depend on what you want to do. Rust code requires more upfront work to architect the application, but if there are existing mature frameworks for what you want to do, they can expose a much better interface than Zig could and you will have far less time spent debugging. With Leptos and Dioxus we are also getting to the point where Rust is getting good frameworks even for gui applications and things it was historically less good at.
@TechBuddy_
@TechBuddy_ 9 ай бұрын
@@BosonCollider great response. I love this answer to a very dumb question that I don't even remember I asked 😂
@ko-Daegu
@ko-Daegu 11 ай бұрын
0:42 How there’s nothing like that fro TypeScript when we can do something like type paymentMethod = Cash | PayPal | Visa This is a taggedUniom aka variant aka sum type
@armax00
@armax00 11 ай бұрын
many of the features mentioned are also in kotlin and swift. Sounds like something interesting to try at least for the fun of it... but the... I need to learn lua really
@NihilistiPekka
@NihilistiPekka 11 ай бұрын
Cool! But why would I trust to Cypher from the Matrix?
@mohamedolabi493
@mohamedolabi493 11 ай бұрын
bro i dont know why but i love u
@pazergmx
@pazergmx 11 ай бұрын
What about the performance field?
@nomoredarts8918
@nomoredarts8918 11 ай бұрын
From now on I'll be asking about Roc
@kpopalitfonzelitaclide2147
@kpopalitfonzelitaclide2147 11 ай бұрын
Zig could be used in the linux jernel instead of rust
@JakeHemmerle
@JakeHemmerle 10 ай бұрын
i think zig has a huge potential in the Wasm world. for perspective, i write and design Rust/Wasm that is shared between mobile, browser, and desktop. Zig toolchain executing completely in Wasm (eg compile Zig to Wasm or link Wasm components together, all *in* Wasm) seems to introduce a new paradigm of portable development and execution. we’re not using zig for anything prod ready yet, but i think Zigs foundation in Wasm might beat out Rust in the long term. i’m excited to see the package management system and compiler integrate with the Wasm pre-spec stuff (eg. Wasm component model). Keep going zig!
@shrin210
@shrin210 4 ай бұрын
With Zig in wasm, can we write web pages in Zig rather than in Reactjs ?
@equivocator7727
@equivocator7727 11 ай бұрын
In my mind, the biggest drawback to Zig is that its basic building blocks are slightly more complicated than is ideal for making anything simple and it currently doesn't offer a way to reduce that workload with defaults. In a lot of cases, specifying or creating an allocator is a super powerful feature, but requiring it 100% of the time is a bit much IMO. Its ergonomics are largely super nice, but in order to be a proper C replacement, it needs to allow a simpler workflow for example for command line tools like you mentioned. I think that could be achieved by creating some reasonable defaults.
@iankaranja7765
@iankaranja7765 11 ай бұрын
Middle-ground languages that care about memory but don't want to burden the programmer always end up as complicated piles of garbage! If using an allocator everywhere is too much of a hassle, find a language with a garbage collector!
@equivocator7727
@equivocator7727 11 ай бұрын
@@iankaranja7765 I see no reason to go to such extremes when a defaulting scheme would completely solve the problem for both cases.
@iankaranja7765
@iankaranja7765 11 ай бұрын
Given the philosophy of zig, I doubt that will happen. Consider that the language doesn't even provide a default print function. Personally, I love the philosophy. Zero tolerance for programmer laziness, and I hope it stays that way.
@equivocator7727
@equivocator7727 11 ай бұрын
@@iankaranja7765 To each their own, but that philosophy firmly plants Zig into a niche. If that's what they want then great, but it won't be general purpose that way.
@iankaranja7765
@iankaranja7765 11 ай бұрын
@@equivocator7727 Same niche as C which it is intended to be a better version of. Even in these early days, any C programmer will tell you zig is something special! I am sure most people rather Rust or C++, but Zig will find its intended audience and however small, it will be a passionate one! I think a big stumbling block of most modern languages is trying to appeal to everyone. I am very glad when something opinionated like Zig comes along!
@JerrenT
@JerrenT 11 ай бұрын
zigma balls
@MrR8686
@MrR8686 11 ай бұрын
Real talk I see your point as the developer tooling aspect and POV
@apolloapostolos5127
@apolloapostolos5127 11 ай бұрын
Is turning errors into values the same as the return command in Bash? (It returns the error-code, rather than exit.)
@daltonyon
@daltonyon 2 ай бұрын
Great video, btw now LSP is working and have a package manager, Go is a beast and Rust is hard, Zig comes to simplify Rust Dev life,
@Jaroshevskii
@Jaroshevskii 11 ай бұрын
Try Swift 👽👽👽
@necauqua
@necauqua 10 ай бұрын
I see Rust as being a better C++, and Zig as being a better C Like it's literally C except better, idk
@arkeynserhayn8370
@arkeynserhayn8370 10 ай бұрын
"It's literally C" evaluates as 0
@viniciusjadiscke7675
@viniciusjadiscke7675 11 ай бұрын
@ThePrimeagen did you just talked about DX ( Developer Experience ) ?
@DejaimeNeto
@DejaimeNeto 11 ай бұрын
If this was Java, 720p wouldn't be nearly enough.
@mpoliwczak
@mpoliwczak 11 ай бұрын
Are you using the devel version of zls? I feel like you are using the tagged version. I suggest trying the devel version, for me it works fine.
@109Rage
@109Rage 11 ай бұрын
I think I remember him using Mason, a Neovim package manager to install ZLS automatically. Which is tied to version 0.10.0 it seems. So yeah, not nightly.
@LinucNerd
@LinucNerd 11 ай бұрын
How about 2 weeks of Odin? :)
@wintersakuraa
@wintersakuraa 11 ай бұрын
how to refactor in Neovim? There is no way I can completely switch to neovim because i do is a lot of files and folders moving,, renaming files, and i want the imports also to be refactored. Is there any solution to this problem? So far, I only know how to refactor when renaming the file. But there are problems with transferring folders and files
@danielcoats713
@danielcoats713 11 ай бұрын
I can imagine some of Zig's features, such as comptime, error and optional type handling, etc., being something that can push other languages to adopt more ergonomic features. I'm a bit biased, but C# has been trying to adopt pattern matching syntax because of Rust. Even if their enums suck, and the match arms can't be a block that returns something, and their pattern-matching syntax is pretty clunky, it's so nice to have a way to shorthand an assignment of a variable with multiple branches. To have pattern matching at all is pretty nice. So I'm all for Zig gaining traction, if for nothing else but to make my job nicer to do.
@pingkai
@pingkai 4 ай бұрын
No matter how great you are and how much you want to replace C, it does not give you right to add a redundant "fn" in front of main()
@kevinkkirimii
@kevinkkirimii 11 ай бұрын
The uses I see, embedded systems, mission critical and high performance systems and maybe gaming.
@Sundaiiz
@Sundaiiz 10 ай бұрын
I see that you've seen V [which was my major curiosity] but I was also wondering what you thought about Nim?
@TheThunder005
@TheThunder005 11 ай бұрын
Tom didn't use no IDE, he hashed that shit straight in Vim!
@ThePrimeagen
@ThePrimeagen 11 ай бұрын
always
@TheThunder005
@TheThunder005 11 ай бұрын
@@ThePrimeagen great work! I vote to release a new version of your name to "chadstack"
@meryplays8952
@meryplays8952 3 ай бұрын
After some thought I believe Zig is fantastic for academic courses in algorithms, for creating programming and specification languages, modernize old code and that's it. Already this is way too much.
CoPilot Review: My Thoughts After 6 Months
9:45
ThePrimeagen
Рет қаралды 532 М.
How To Learn A New Programming Language
6:24
ThePrimeagen
Рет қаралды 242 М.
Barriga de grávida aconchegante? 🤔💡
00:10
Polar em português
Рет қаралды 39 МЛН
Зомби Апокалипсис  часть 1 🤯#shorts
00:29
INNA SERG
Рет қаралды 6 МЛН
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 283 М.
Programming on TikTok
6:08
ThePrimeagen
Рет қаралды 303 М.
FULL Introduction To HTMX Using Golang
2:02:31
ThePrimeagen
Рет қаралды 248 М.
Rust Foundation IS DOING WHAT????
8:17
ThePrimeagen
Рет қаралды 325 М.
C++ Game Programmer Tries ZIG for the first time.
5:28
Low Level Game Dev
Рет қаралды 44 М.
The Vanguard Incident
8:11
Ryscu
Рет қаралды 55 М.
I randomized every block's code in Minecraft..
10:38
Element X
Рет қаралды 210 М.
How I would learn to code (If I could start over)
9:16
Jason Goodison
Рет қаралды 4,4 МЛН
Go is blazingly faster than Zig?
8:44
ThePrimeagen
Рет қаралды 160 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 3,5 МЛН
What % of charge do you have on phone?🔋
0:11
Diana Belitskay
Рет қаралды 296 М.
Купите ЭТОТ БЮДЖЕТНИК вместо флагманов от Samsung, Xiaomi и Apple!
13:03
Thebox - о технике и гаджетах
Рет қаралды 53 М.
Как открыть дверь в Jaecoo J8? Удобно?🤔😊
0:27
Суворкин Сергей
Рет қаралды 1,2 МЛН