Learning Zig Part 2

  Рет қаралды 33,069

TheVimeagen

TheVimeagen

Күн бұрын

Пікірлер: 59
@tiedye001
@tiedye001 8 ай бұрын
Variable might be null? THREATEN IT into compliance
@marcusvinson1273
@marcusvinson1273 5 күн бұрын
I've been avoiding Zig after putting so much investment into Rust. But after living vicariously through Primeagen, Zig looks way more enjoyable
@notuxnobux
@notuxnobux 8 ай бұрын
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.
@ForeverZer0
@ForeverZer0 8 ай бұрын
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.
@notuxnobux
@notuxnobux 8 ай бұрын
@@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.
@SimonBuchanNz
@SimonBuchanNz 8 ай бұрын
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)
@IanRiley915
@IanRiley915 8 ай бұрын
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 ;)
@maxoumimaro
@maxoumimaro 8 ай бұрын
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.
@radioJim
@radioJim 2 ай бұрын
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.
@andrebrait
@andrebrait 8 ай бұрын
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)".
@revenevan11
@revenevan11 5 ай бұрын
These 2 videos are really selling me on wanting to learn zig lol
@lack_of_awareness
@lack_of_awareness 8 ай бұрын
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
@notuxnobux
@notuxnobux 8 ай бұрын
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.
@GuyFromJupiter
@GuyFromJupiter 8 ай бұрын
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.
@CatDevz
@CatDevz 8 ай бұрын
Prime in C doing x->y is the same as (*x).y
@ficolas2
@ficolas2 8 ай бұрын
Dereferencing with .*. Is actually pretty awesome, reading left to right, then going to the left, then to the right again, is horrible
@TheDolphiner
@TheDolphiner 8 ай бұрын
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.
@TheTrippyTerminal
@TheTrippyTerminal 8 ай бұрын
Btw vim motions jkl works on youtube in browser as well. j to go back, l to go forward, k to pause.
@helanomiguel3783
@helanomiguel3783 8 ай бұрын
Not using deodorant in Brazil is almost a crime. Please don't do that ever again 😆
@user-uf4lf2bp8t
@user-uf4lf2bp8t 5 ай бұрын
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.
@metaltyphoon
@metaltyphoon 8 ай бұрын
The worst part about zig is anytype. You have to “figure” out all methods a type implement if you want to have a “interface”
@_orangutan
@_orangutan 8 ай бұрын
Finally Zig is catching steam. 1.0 is around the corner lads. Elixir + Zig = MUAH!!!!
@Tobsson
@Tobsson 8 ай бұрын
Zig 1.0 is probably years away knowing what they want zig to be.
@Vergillo
@Vergillo 7 ай бұрын
@@Tobssonseeing their milestones and release cycles on GitHub makes me feel like 1.0 is as close as year of the Linux lol
@valentinrafael9201
@valentinrafael9201 3 ай бұрын
Around the corner? It’s around some corner for sure, but it sounds like you’re from 2030+. Have we completely ditched fossil fuel?
@adamsribz
@adamsribz 8 ай бұрын
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.
@MrMeltdown
@MrMeltdown 8 ай бұрын
Orelse? Is that not the // operator in Perl?
@ark_knight
@ark_knight 8 ай бұрын
Is he not streaming to youtube while in Brazil?
@MCroppered
@MCroppered 8 ай бұрын
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
@albumin30days90
@albumin30days90 8 ай бұрын
where are you?
@Microphunktv-jb3kj
@Microphunktv-jb3kj 2 ай бұрын
"why use that inferior editor vscode" alsp prime: 30:07 :D:D:DD autocomplete sucks it doesnt suck zls with vscode extension
@TheTrippyTerminal
@TheTrippyTerminal 8 ай бұрын
No music sound to us.
@sa-hq8jk
@sa-hq8jk 4 ай бұрын
that was intentional
@kevinkkirimii
@kevinkkirimii 8 ай бұрын
what would be the use case for a constant pointer ?
@RajarshiKhatua100
@RajarshiKhatua100 8 ай бұрын
Huffman?
@notuxnobux
@notuxnobux 8 ай бұрын
huffman coding is a way to compress data. It's used by jpeg, png, zip files, etc.
@RajarshiKhatua100
@RajarshiKhatua100 8 ай бұрын
@@notuxnobux I know, but why it's there
@RajarshiKhatua100
@RajarshiKhatua100 8 ай бұрын
@@notuxnobux NSO stuff
@beeplove7
@beeplove7 8 ай бұрын
@@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.
@RajarshiKhatua100
@RajarshiKhatua100 8 ай бұрын
@@beeplove7 oh, I get it now
@JLarky
@JLarky 8 ай бұрын
53:15 this is awkward
@platin2148
@platin2148 8 ай бұрын
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?
@UnidimensionalPropheticCatgirl
@UnidimensionalPropheticCatgirl 8 ай бұрын
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
@platin2148
@platin2148 8 ай бұрын
@@UnidimensionalPropheticCatgirl So it’s static assert on assignment. Well any access to a thing that isn’t modified is thread safe.
@SlightRemorse
@SlightRemorse 8 ай бұрын
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.
@platin2148
@platin2148 8 ай бұрын
@@SlightRemorse So it’s inferring that so you can put the decorative keyword there.
@platin2148
@platin2148 8 ай бұрын
@@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-2323
@matress-4-2323 8 ай бұрын
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.
@steveoc64
@steveoc64 8 ай бұрын
Have a look at jetzig- it’s under heavy development, but it aims to provide a DX similar to ruby on rails
@matress-4-2323
@matress-4-2323 8 ай бұрын
@@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-2323
@matress-4-2323 8 ай бұрын
@@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.
@steveoc64
@steveoc64 8 ай бұрын
@@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-qp2yw
@Ash-qp2yw 8 ай бұрын
TLDR where Prime is /why?
@UnidimensionalPropheticCatgirl
@UnidimensionalPropheticCatgirl 8 ай бұрын
conference in brazil, idk why
@opposite342
@opposite342 8 ай бұрын
He goes to Brazil basically just for a meet up (inside a conference). He live reacted TeeJ's and BigBoxSWE's video there lol.
@ficolas2
@ficolas2 8 ай бұрын
LUA CONFERENCE BRAZIL MENTIONED LUA MENTIONED NVIM BTW
@itsmenewbie03
@itsmenewbie03 8 ай бұрын
Early ~
i fell for mocks again...
9:08
TheVimeagen
Рет қаралды 30 М.
Zig programming language tutorial - Part 1
46:47
Matt Freire
Рет қаралды 38 М.
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН
Вопрос Ребром - Джиган
43:52
Gazgolder
Рет қаралды 3,8 МЛН
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
БОЙКАЛАР| bayGUYS | 27 шығарылым
28:49
bayGUYS
Рет қаралды 1,1 МЛН
Trying Zig Part 1
1:30:00
TheVimeagen
Рет қаралды 121 М.
Building An Ascii Particle System
1:45:39
TheVimeagen
Рет қаралды 139 М.
The Vlang Drama
43:35
ThePrimeTime
Рет қаралды 104 М.
More Zig Learning
33:33
TheVimeagen
Рет қаралды 13 М.
Zig for the Uninitiated: Pointers, Arrays, and Slices
19:03
Tyler Calder
Рет қаралды 4,2 М.
My Zig Experience | Prime Reacts
38:13
ThePrimeTime
Рет қаралды 159 М.
My First Zig Interface
2:19:28
TheVimeagen
Рет қаралды 43 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 160 М.
Designing My First Game w/ Casey Muratori
1:42:46
ThePrimeTime
Рет қаралды 208 М.
TCP Packets In Vim and Golang
2:39:21
TheVimeagen
Рет қаралды 32 М.
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН