Variable might be null? THREATEN IT into compliance
@marcusvinson12735 күн бұрын
I've been avoiding Zig after putting so much investment into Rust. But after living vicariously through Primeagen, Zig looks way more enjoyable
@notuxnobux8 ай бұрын
40:27 files in zig are anonymous structs yes, it's like the file is a struct without the const name = struct { header part, so you can write exact same code as in a struct there, so you can have fields separated by , instead of ;. When you import the file with const Name = @import("Name.zig"); you can do const name = Name{}; since files are structs, you can use metaprogramming on files to find all fields (variables, structs, functions, etc) that is defined in a file. That makes metaprogramming work on everything without any special weird cases.
@ForeverZer08 ай бұрын
I thought it was strange at first, but in practice it is actually pretty useful. I am still very much a Zig amateur, but just discovered how you can use this feature to make your files the "type" being defined within them with something like "const MyType = @This();", and not have to nest all your functions/fields within the opening/closing braces of a struct definition. It also makes importing a cleaner looking, so you can do "const MyType = @import("MyType.zig");" instead of "const MyType = @import("my_type.zig").MyType;" It almost gives me Lua vibes where you can require the file as the thing.
@notuxnobux8 ай бұрын
@@ForeverZer0 Yeah and it also makes the compiler much simpler. I wrote my own compiler once and I made files structs as well naturally. If your code can handle referencing a struct then importing a file and referencing data in that will automatically work as well, no need for a separate "File" type.
@SimonBuchanNz8 ай бұрын
Traditionally you need to distinguish "static members" (using the container as a namespace) and "instance members" (treating the container as a template) - how does that work? In many script-ier languages the module level (barring import/export stuff) is identical to function bodies, so it's not a totally new idea (JavaScript commonjs implemented a module system using this fact, for example)
@IanRiley9158 ай бұрын
Nothing captures the life of a dev better than watching prime perk up at the idea of using his phone for chat only to find out that its battery is nearly dead ;)
@maxoumimaro8 ай бұрын
Thanks Prime for doing this learning ziglings, seeing you start this on part1 gave me the boost to just do it and I am currently on exercise 97 since then. You are going to like the next few parts. What I prefered was getting into the compile time code, it is very interesting.
@radioJim2 ай бұрын
5:39 That really is a crazy example. Using identifiers that sound like keywords is one of the worst things you can do when you're literally teaching the keywords and syntax! When in doubt, just prepend "my_" to it or something.
@andrebrait8 ай бұрын
5:36 you need to see "const u8" as its own type. So then the pointer becomes this: const p: *(const u8) = &a; (I added the parentheses for clarity) It's a constant "p" of type "pointer to a (constant u8)".
@revenevan115 ай бұрын
These 2 videos are really selling me on wanting to learn zig lol
@lack_of_awareness8 ай бұрын
im not sure why he says the var const pointer stuff is weird, it literally behaves the same way in rust LOL. `let` is `const` , `let mut` is `var`, `&T` is `*const T`, `&mut T` is `*T` edit* he figured it out
@notuxnobux8 ай бұрын
47:31 the variable is const but not the pointer. The way its done is zig makes sense. On the left side is the variable definition and on the right side is the type definition. const is attached to the variable name so the variable is const, there is no const attached to the type so the type is not const.
@GuyFromJupiter8 ай бұрын
I don't dislike prefix derefs, but I do hate that in C pointer declarations and type casts have almost the exact same syntax as dereferencing a pointer. I find Rust's way of using & for reference types to be much more natural.
@CatDevz8 ай бұрын
Prime in C doing x->y is the same as (*x).y
@ficolas28 ай бұрын
Dereferencing with .*. Is actually pretty awesome, reading left to right, then going to the left, then to the right again, is horrible
@TheDolphiner8 ай бұрын
Zig's dereference syntax is a wonderful example of going with a familiar C-like syntax, but still rethinking all the choices. Similar example I like is just how much I adore zig's multiline strings.
@TheTrippyTerminal8 ай бұрын
Btw vim motions jkl works on youtube in browser as well. j to go back, l to go forward, k to pause.
@helanomiguel37838 ай бұрын
Not using deodorant in Brazil is almost a crime. Please don't do that ever again 😆
@user-uf4lf2bp8t5 ай бұрын
rust does the "const ptr: *const u8; var mut_ptr: *const u8" the same as zig with "let ptr: const* u8; let mut mut_ptr: const*u8". in all cases, the values at the pointers cannot be changed, but both of the mut_ptr's can be reassigned, and neither of the ptr's can be reassigned.
@metaltyphoon8 ай бұрын
The worst part about zig is anytype. You have to “figure” out all methods a type implement if you want to have a “interface”
@_orangutan8 ай бұрын
Finally Zig is catching steam. 1.0 is around the corner lads. Elixir + Zig = MUAH!!!!
@Tobsson8 ай бұрын
Zig 1.0 is probably years away knowing what they want zig to be.
@Vergillo7 ай бұрын
@@Tobssonseeing their milestones and release cycles on GitHub makes me feel like 1.0 is as close as year of the Linux lol
@valentinrafael92013 ай бұрын
Around the corner? It’s around some corner for sure, but it sounds like you’re from 2030+. Have we completely ditched fossil fuel?
@adamsribz8 ай бұрын
glorp_access3 isn't a "pointer to a constant", though. It's a constant pointing to a mutable var (&glorp). that's how i read it. anyways i really like this series! EDIT: ok, you addressed this haha.
@MrMeltdown8 ай бұрын
Orelse? Is that not the // operator in Perl?
@ark_knight8 ай бұрын
Is he not streaming to youtube while in Brazil?
@MCroppered8 ай бұрын
I’ve just realised who you remind me of. Ive finally worked it out. Beavis. You are Beavis from Beavis and Butthead. Yeyeyyeyeyeye = boioioioioioioing. You know it
@albumin30days908 ай бұрын
where are you?
@Microphunktv-jb3kj2 ай бұрын
"why use that inferior editor vscode" alsp prime: 30:07 :D:D:DD autocomplete sucks it doesnt suck zls with vscode extension
@TheTrippyTerminal8 ай бұрын
No music sound to us.
@sa-hq8jk4 ай бұрын
that was intentional
@kevinkkirimii8 ай бұрын
what would be the use case for a constant pointer ?
@RajarshiKhatua1008 ай бұрын
Huffman?
@notuxnobux8 ай бұрын
huffman coding is a way to compress data. It's used by jpeg, png, zip files, etc.
@RajarshiKhatua1008 ай бұрын
@@notuxnobux I know, but why it's there
@RajarshiKhatua1008 ай бұрын
@@notuxnobux NSO stuff
@beeplove78 ай бұрын
@@RajarshiKhatua100 it was a roadmap for the stream. Learning zig was the first segment and Huffman was the last segment where he implemented Huffman encoding in his ASCII doom project.
@RajarshiKhatua1008 ай бұрын
@@beeplove7 oh, I get it now
@JLarky8 ай бұрын
53:15 this is awkward
@platin21488 ай бұрын
Const is fundamentally useless the compiler does already know waht’s constant and what is not. Does this help the compiler to build the SSA form of the code in anyway?
@UnidimensionalPropheticCatgirl8 ай бұрын
consts are thread safe, so it’s good to have them known, beyond that it’s just safety feature, so it throws errors when you try to assign to it. It doesn’t help ssa as far as I know
@platin21488 ай бұрын
@@UnidimensionalPropheticCatgirl So it’s static assert on assignment. Well any access to a thing that isn’t modified is thread safe.
@SlightRemorse8 ай бұрын
With v0.12 if you have a var declaration that is never modified the compiler actually complains that you should turn the var declaration into a const one instead.
@platin21488 ай бұрын
@@SlightRemorse So it’s inferring that so you can put the decorative keyword there.
@platin21488 ай бұрын
@@Tom-dd3vl Well as far as i remember compilers don’t even use it as type hint especially LLVM seems to have droped that concept completely to a part. But i suspect const in Zig is more like constexpr in C++, where const is simply too weak to apply any meaningful opt.
@matress-4-23238 ай бұрын
this may be unpopular opinion but i think zig is more complex than rust for things outside of systems programming. for systems programming it's simpler but for like web backends and things like that it's way more complex. the syntax is simpler but it feels more low level in those contexts. that's my personal experience from using both.
@steveoc648 ай бұрын
Have a look at jetzig- it’s under heavy development, but it aims to provide a DX similar to ruby on rails
@matress-4-23238 ай бұрын
@@steveoc64 yeah, that's actually what i tried. maybe a different api would be more appealing to me. i tried that and zap and i liked zap more but there's so much boilerplate for like a basic middleware implementation. the issue is all of the lower level code, which is why i think rust works better in that context, because it feels a lot more like a higher level language. the borrow checker makes it feel like higher level. zig is a lot closer to c which has benefits for systems programming, but other areas is too verbose in my opinion. i'm willing to give it another shot in the future though when the ecosystem matures more.
@matress-4-23238 ай бұрын
@@steveoc64 take a look at axum and loco and you can kind of see what i mean. it's still complex relative to go or typescript, but less complex relative to zig for web. at least for the moment, because it's still very early in development for zig. i'll give zig a couple of years and try it out again.
@steveoc648 ай бұрын
@@matress-4-2323 yeah, I’ve done a tonne of go in prod (8 years) .. have used Axum (don’t like) Am currently developing using http.zig - which sort of fits in similar to go, although the middleware (dispatcher) interface is a bit different. I’m working on my fork of that, building a framework specifically for HTMX. Just taking my time with it for now. But again, even http.zig is moving fast and getting better. Zig is ideal if you want to get involved contributing to building the next great framework.. but can be frustrating if you just want to start building apps right now.
@Ash-qp2yw8 ай бұрын
TLDR where Prime is /why?
@UnidimensionalPropheticCatgirl8 ай бұрын
conference in brazil, idk why
@opposite3428 ай бұрын
He goes to Brazil basically just for a meet up (inside a conference). He live reacted TeeJ's and BigBoxSWE's video there lol.
@ficolas28 ай бұрын
LUA CONFERENCE BRAZIL MENTIONED LUA MENTIONED NVIM BTW