Learning Zig Part 2

  Рет қаралды 22,505

TheVimeagen

TheVimeagen

Ай бұрын

LIVE ON TWITCH: / theprimeagen
Become a backend engineer. Its my favorite site
boot.dev/?promo=PRIMEYT
This is also the best way to support me is to support yourself becoming a better backend engineer.
Get in on Discord: / discord
Get in on Twitter: / theprimeagen
Got Something For Me to Read or Watch??:
/ theprimeagenreact

Пікірлер: 55
@tiedye001
@tiedye001 28 күн бұрын
Variable might be null? THREATEN IT into compliance
@notuxnobux
@notuxnobux 28 күн бұрын
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 28 күн бұрын
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 28 күн бұрын
@@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 28 күн бұрын
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 25 күн бұрын
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 28 күн бұрын
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.
@andrebrait
@andrebrait 28 күн бұрын
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)".
@_orangutan
@_orangutan 28 күн бұрын
Finally Zig is catching steam. 1.0 is around the corner lads. Elixir + Zig = MUAH!!!!
@Tobsson
@Tobsson 26 күн бұрын
Zig 1.0 is probably years away knowing what they want zig to be.
@notuxnobux
@notuxnobux 28 күн бұрын
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.
@ficolas2
@ficolas2 28 күн бұрын
Dereferencing with .*. Is actually pretty awesome, reading left to right, then going to the left, then to the right again, is horrible
@TheDolphiner
@TheDolphiner 28 күн бұрын
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.
@axisaligned9799
@axisaligned9799 28 күн бұрын
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
@kevinkkirimii
@kevinkkirimii 27 күн бұрын
what would be the use case for a constant pointer ?
@MrMeltdown
@MrMeltdown 27 күн бұрын
Orelse? Is that not the // operator in Perl?
@ark_knight
@ark_knight 28 күн бұрын
Is he not streaming to youtube while in Brazil?
@adamsribz
@adamsribz 24 күн бұрын
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.
@helanomiguel3783
@helanomiguel3783 28 күн бұрын
Not using deodorant in Brazil is almost a crime. Please don't do that ever again 😆
@CatDevz
@CatDevz 28 күн бұрын
Prime in C doing x->y is the same as (*x).y
@MCroppered
@MCroppered 27 күн бұрын
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
@GuyFromJupiter
@GuyFromJupiter 28 күн бұрын
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.
@TheTrippyTerminal
@TheTrippyTerminal 26 күн бұрын
No music sound to us.
@AChonkyBird
@AChonkyBird 28 күн бұрын
Back to gruvbox.
@TheTrippyTerminal
@TheTrippyTerminal 26 күн бұрын
Btw vim motions jkl works on youtube in browser as well. j to go back, l to go forward, k to pause.
@albumin30days90
@albumin30days90 27 күн бұрын
where are you?
@rajarshikhatua100
@rajarshikhatua100 28 күн бұрын
Huffman?
@notuxnobux
@notuxnobux 28 күн бұрын
huffman coding is a way to compress data. It's used by jpeg, png, zip files, etc.
@rajarshikhatua100
@rajarshikhatua100 28 күн бұрын
@@notuxnobux I know, but why it's there
@rajarshikhatua100
@rajarshikhatua100 28 күн бұрын
@@notuxnobux NSO stuff
@beeplove7
@beeplove7 28 күн бұрын
@@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 28 күн бұрын
@@beeplove7 oh, I get it now
@JLarky
@JLarky 28 күн бұрын
53:15 this is awkward
@metaltyphoon
@metaltyphoon 28 күн бұрын
The worst part about zig is anytype. You have to “figure” out all methods a type implement if you want to have a “interface”
@Ash-qp2yw
@Ash-qp2yw 28 күн бұрын
TLDR where Prime is /why?
@UnidimensionalPropheticCatgirl
@UnidimensionalPropheticCatgirl 28 күн бұрын
conference in brazil, idk why
@opposite342
@opposite342 28 күн бұрын
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 28 күн бұрын
LUA CONFERENCE BRAZIL MENTIONED LUA MENTIONED NVIM BTW
@porcupinetree-bb3zg
@porcupinetree-bb3zg 27 күн бұрын
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 25 күн бұрын
Have a look at jetzig- it’s under heavy development, but it aims to provide a DX similar to ruby on rails
@porcupinetree-bb3zg
@porcupinetree-bb3zg 25 күн бұрын
@@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.
@porcupinetree-bb3zg
@porcupinetree-bb3zg 25 күн бұрын
@@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 25 күн бұрын
@@porcupinetree-bb3zg 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.
@platin2148
@platin2148 28 күн бұрын
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 28 күн бұрын
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 28 күн бұрын
@@UnidimensionalPropheticCatgirl So it’s static assert on assignment. Well any access to a thing that isn’t modified is thread safe.
@SlightRemorse
@SlightRemorse 28 күн бұрын
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 28 күн бұрын
@@SlightRemorse So it’s inferring that so you can put the decorative keyword there.
@Tom-dd3vl
@Tom-dd3vl 28 күн бұрын
Comments are useless because the compiler already knows what to compile your code to. Just like comments, const exists to help the programmer reading and writing the code. You'll never accidentally modify it. This is especially helpful in cases where modifying it would be a mistake 100% of the time, like captured values. That all aside, const does have a benefit. Constants can be inlined. If the compiler had to find every reference of every variable to make sure it's constant that'll bog down compile times. Finding every reference of every variable also becomes impossible as soon as pointers are involved. It gets too complex for the compiler to follow.
@itsmenewbie03
@itsmenewbie03 28 күн бұрын
Early ~
Trying Zig Part 1
1:30:00
TheVimeagen
Рет қаралды 71 М.
Huffman Encoding First Try
1:00:00
TheVimeagen
Рет қаралды 17 М.
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 36 МЛН
100😭🎉 #thankyou
00:28
はじめしゃちょー(hajime)
Рет қаралды 56 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3,4 МЛН
MOM TURNED THE NOODLES PINK😱
00:31
JULI_PROETO
Рет қаралды 24 МЛН
Learning Zig | Day 1
2:07:11
TheVimeagen
Рет қаралды 22 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel
Рет қаралды 27 М.
Creating Game Of Life In Neovim
43:55
TheVimeagen
Рет қаралды 22 М.
JavaScript Visualized - Execution Contexts
11:41
Lydia Hallie
Рет қаралды 35 М.
Why i think C++ is better than rust
32:48
ThePrimeTime
Рет қаралды 269 М.
I Rewrote My Entire Neovim Config...
11:09
TJ DeVries
Рет қаралды 33 М.
Code Review: Holy C Lexer
8:45
TheVimeagen
Рет қаралды 68 М.
You Are WRONG About 0 Based Indexing
25:02
ThePrimeTime
Рет қаралды 217 М.
Learning Zig : Creating a Stack (comptime)
1:38:43
TheVimeagen
Рет қаралды 10 М.
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 10 МЛН
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,7 МЛН
📱 SAMSUNG, ЧТО С ЛИЦОМ? 🤡
0:46
Яблочный Маньяк
Рет қаралды 1,9 МЛН
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 21 МЛН
Iphone or nokia
0:15
rishton vines😇
Рет қаралды 997 М.