The Road to Zig 1.0 - Andrew Kelley

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 369

  • @DanielSantaCruz
    @DanielSantaCruz 2 ปีที่แล้ว +68

    "C was broken, and I fixed it" -- haha, love it.

  • @connorm9176
    @connorm9176 4 ปีที่แล้ว +253

    C used to be my favorite language, but there were still some things I didn't like about it. Zig seems like everything I wish C was, really excited for the 1.0 release

    • @TheBrainDunne
      @TheBrainDunne 3 ปีที่แล้ว +6

      I agree

    • @TheSulross
      @TheSulross 3 ปีที่แล้ว +18

      before I learned about Zig I had been fantasizing about creating a C-like language that addresses various flaws and has a wee bit of modernity (like defer from Go); was just going to do this as my own little research project. Now that I've seen Zig, well it checks off everything I wanted to address, its open source, has a going community, and a fair amount of maturity of implementation even though its such a new language. Am now going to spend all that time learning about Zig.

    • @hafidmahdi1329
      @hafidmahdi1329 2 ปีที่แล้ว

      frfr really excited

    • @drygordspellweaver8761
      @drygordspellweaver8761 2 ปีที่แล้ว

      Wish they would drop the const keyword though

    • @origamibulldoser1618
      @origamibulldoser1618 2 ปีที่แล้ว

      @@drygordspellweaver8761 mutability is important.

  • @jstenberg3192
    @jstenberg3192 2 ปีที่แล้ว +33

    I am not a coder or tech guy...im a business person trying to learn enough to understand why the tech world can't solve my problems in a way that is fast, secure and reasonably future proof. What a fascinating world you all live in and I'm glad people are trying improve things.

    • @peezieforestem5078
      @peezieforestem5078 2 ปีที่แล้ว +16

      It's a very complex issue, I will try to outline the 3 main reasons:
      1) There's a strong market pressure to release ASAP, even at a sacrifice for quality. It almost doesn't matter how bad your product is, because if it's the only product for a year before any other release, well, there's just no alternatives.
      It's such a massive first mover advantage that the whole industry is geared towards releasing things fast, so a lot of the tools and decisions stem from that, and this ecosystem naturally forces others to incorporate these tools, or releases take even longer, because now everything needs to be done from scratch.
      2) Another strong pressure is towards making the tech accessible to as many people as possible. The good programmer pool is pretty limited and there's an extremely strong competition. In many cases, a medium programmer or even a bad programmer is better than no programmer, but if the tools are too complex, well, the medium and bad programmers can't use them.
      This creates a trend of dumbing down the tools so that more people can use them, which in turns means there are more programmers who can get the job done, meaning there's less competition, because not every application is an airplane software. This is generally good, but the side effect is that you get the majority of the tools and programmers that do a bad job, and from your perspective, it's very difficult to separate the weed from the chaff.
      In other words, it's not so much that the tech world can't solve your problems, it's more like it's very difficult to find people and tools in the tech world that can, and this will continue to be the case until there's more demand for software than there's supply of competent programmers.
      3) It's beneficial for programmers to write bad software, and write it moderately slowly. If you write clean, maintainable, fast code and do it quickly, well, in a year you won't have a job, because you've done the lion's share of work, and now a cheaper, less qualified person can maintain it. On the other hand, if you write a convoluted mess that nobody except you can touch without the risk of it breaking, take your pace and leave a lot of room for "improvements", you've secured a job for a long time.

    • @shrin210
      @shrin210 ปีที่แล้ว +3

      Are you really not a tech guy?
      You are watching a video that programmers don't even watch or get to know.

    • @jstenberg3192
      @jstenberg3192 ปีที่แล้ว +1

      @@shrin210 Finance major Econ minor. I mean I play Hell Let Loose and did a simple BASIC program in 1984....so if that is a tech guy..ok!

    • @shrin210
      @shrin210 ปีที่แล้ว

      @@jstenberg3192
      Sir, please explain me what motivates you to learn at this age and not even a tech guy anymore.
      Probably your motivation will be inspiration for me to get in discipline.

    • @marcelocruz7644
      @marcelocruz7644 8 หลายเดือนก่อน +1

      @peezieforestem5078 That is a poor and weak way of thinking(about 3), one should do things good wherever it is done. If you lose your job doing the good way, the job is possibly bad and more importantly you finished your mission there, in your scenario you become bad in a bad job that you created or is reinforcing while there are better ones out there. Improve the life for you and the others doing what is good. Also, think with me, doing the good is a thing, giving all your time and life energy is another. There are lots of people giving lots of energy but still doing a bad work, that is a lack of self-control and learning.

  • @skaruts
    @skaruts 3 ปีที่แล้ว +232

    I'm not hyped by Zig's syntax, I'm still on the fence, but I have to admit this guy is right down to earth:
    *_"If we're always gonna be lazy, then we better make the lazy path the correct one."_*
    Exactly. People are always trying to change what realistically will never change. You cannot solve a problem by going against the natural way of things and having unrealistic expectations about people. If the road goes left, the solution has to involve turning left.

    • @bogdanpanchuk296
      @bogdanpanchuk296 3 ปีที่แล้ว +7

      Yeah, and people try solve problem of turning left by turning right, and when they fail they say "we didn't turn right enough", which is true (270° + 360° * N turn is always possible), but utterly ridiculous.

    • @fennecbesixdouze1794
      @fennecbesixdouze1794 3 ปีที่แล้ว +5

      @@bogdanpanchuk296 I don't think you understand what analogies are.

    • @bogdanpanchuk296
      @bogdanpanchuk296 3 ปีที่แล้ว +11

      @@fennecbesixdouze1794 "we need MORE layers of the abstraction" etc.

    • @monsterhunter445
      @monsterhunter445 2 ปีที่แล้ว +5

      "natural way of things" what exactly is the natural way of things I think you are fundamentally underestimating how hard it is to answer that question. After all if we use natural in it's literal sense. Programming languages are artificial constructs not natural in any way. So I don't see how we can know the natural way. I do agree with your broader point about making languages "safer" because we are inherently "lazy"

    • @skaruts
      @skaruts 2 ปีที่แล้ว +5

      @@monsterhunter445 clearly the natural way for people to go is to write less code and cleaner, rather than more code and cluttered. It's not hard to see it.
      At the very least, though, when you try to go against something and it still never goes the way you want, then you know that's one way it will ever go. I can think of quite a few unrelated examples where people keep trying to make things go the way they never will.

  • @joshuaclayton6940
    @joshuaclayton6940 8 หลายเดือนก่อน +14

    I love the involuntary case study of the slideshow breaking just as Andrew was making a joke about software being broken.

  • @michaelharrington6698
    @michaelharrington6698 2 ปีที่แล้ว +17

    The native printf language support with the comptime support then showing how comptime supports generics was awesome. Nicely done!

  • @SourceCodeDeleted
    @SourceCodeDeleted 4 ปีที่แล้ว +89

    I think he makes a lot of good points and I use C a lot.

  • @opensourcedev22
    @opensourcedev22 ปีที่แล้ว +12

    I cut my teeth on C 2 decades ago. This dude knows the pain points and I'm glad he has enough time and resources to deliver. If Zig is the eventual outcome, so be it. It looks fine to me. Great job

  • @edgeeffect
    @edgeeffect 11 หลายเดือนก่อน +2

    I'm SO pleased that there's finally someone out there among the "movers and shakers" throwing a little shade at the C preprocessor... I've been quietly hating it for about 25 years now.

  • @AnonEMoose-mr8jm
    @AnonEMoose-mr8jm 5 ปีที่แล้ว +105

    Really excited to see this language grow and develop.
    Many higher lever languages are first written in C. I wonder how quality will increase as more projects adopt zig?
    In particular, my interest is in security and distributed systems. Zig seems like the perfect language to design a secure higher level language in.

    • @SianaGearz
      @SianaGearz 3 ปีที่แล้ว +7

      And yet Zig has no ambition of being a secure language; it only explores elegant ways to solve some of C's fundamental problems. Arguably higher-level language implementations are complex software in and of themselves, with no low level ambitions, they don't manipulate hardware directly, they receive text and output machine code of some kind (real machine or virtual machine), and would benefit more from being developed in a security and correctness oriented language, and they also benefit quite a bit from expressive capabilities of higher level languages, so C++ seems to be more commonly used than C, but i might be wrong, i haven't actually done a tally. The most common strategy for higher level languages is for the canonical implementation being written in itself, examples being D, Rust, Nim, Ocaml, Scala, Vala, Sather, Go and so on. The first implementation in this case was usually written in C or C++ but after a short development stage of usually only a handful months, nothing of this implementation remains. The initial implementation (bootstrapper) is usually quite deliberately shoddy, as it needs to only be able to compile the smallest useful subset of the language, from where on it's better off rewritten in the target language, and its quality and development velocity wouldn't necessarily improve by choosing a better language, and is also irrelevant over the useful life of the target language.

    • @SimonBuchanNz
      @SimonBuchanNz 3 ปีที่แล้ว +3

      If you want secure, Rust is a lot closer than Zig. We still don't quite have the language that *really* cares about security as a whole, to my knowledge, at least with the C ABI, no GC restrictions in this talk.

    • @leosanchez9115
      @leosanchez9115 2 ปีที่แล้ว +1

      @@SimonBuchanNz I'm not too crazy about Rust. The languages that care about security often make use of capabilities-based security. Check out the Pony programming language and look into Mark Miller's work.

    • @SimonBuchanNz
      @SimonBuchanNz 2 ปีที่แล้ว +1

      @@leosanchez9115 I thought pony talked a good game, but I'm yet to be convinced by the little I've seen so far. Capability based security is clearly the way to go in general though.

    • @seanknowles9985
      @seanknowles9985 ปีที่แล้ว

      You predicted the future ;) we now have Bun in the javascript world.

  • @mullergyula4174
    @mullergyula4174 2 ปีที่แล้ว +15

    I love your approach. Rust sounds like something that can get very complicated.

  • @FostersLagerMorphs
    @FostersLagerMorphs ปีที่แล้ว +3

    A few days ago, I watched Herb Sutter's talk "The Evolution of C++ - A Typescript for C++" and he highlighted the importance of an easy migration path (i.e. backward compatibility) when evolving a language (the decade it took to move from Python 2 to 3 being a prime example). That's where my mind went when Andrew mentioned that Zig can compile C code. I do a lot of embedded systems work at the moment, and the cross-compilation feature plus the ability to easily work with C has my interest.

    • @nextlifeonearth
      @nextlifeonearth ปีที่แล้ว +1

      This is particularly toolchain support rather than language support of C. You can declare a C function/type in zig and use it as long as you link it. The build system makes it easy to link C files after building them, but you can't just act as if a C function exists or by pointing it at a .h file. You can generate a .zig file from a .h file though and use it, but you can do that with a lot of languages.
      So the interop is not as easy as using C from C++, but the build system makes up for the language limitation.

    • @Sandromatic
      @Sandromatic ปีที่แล้ว +1

      @@nextlifeonearth you can, practically though? @cImport, then you can basically #include etc. yes, this is done by converting it to .zig, but also, like, its builtin and as simple as doing a #include really.

  • @eigentensor
    @eigentensor ปีที่แล้ว +1

    This is probably the single best talk I've ever seen, bravo

  • @enverhoxha2698
    @enverhoxha2698 4 ปีที่แล้ว +27

    go also has error return traces, but requires the programmer to manually wrap errors before returning them. Zig seems a lot nicer.

    • @mgord9518
      @mgord9518 2 ปีที่แล้ว +5

      After doing a few months of Zig after nothing but Go and Python, it's easy to notice that Go's error handling really sucks ass.

  • @Russtopia
    @Russtopia 5 ปีที่แล้ว +139

    Amazing. The elegance of the solutions described here are just ... wow.
    As a recent convert to Go, part of me wishes somehow the two could combine, but Go started down a road of requiring an (albeit very good IMHO) GC and segmented/copied stack architecture which is incompatible with plain C (without the usual use of language bindings, etc.), making any sort of bi-directional ABI compabitility with plain C such as Zig offers, implausible.
    So... with zig's deep ability to both *use* C headers/libs, and its ability to *emit* true C-world ABI binaries, there is an amazing opportunity here to *incrementally* (key word) migrate the C-based foundation of all modern OSes and standard libraries to a safer, cleaner language.
    If zig could become self-compiling (eliminate LLVM, or port LLVM to zig).. C could be eliminated?
    Existing OSes (even compilation units within an existing kernel -- imagine re-writing Linux, file by file, to zig without breaking compatibility), drivers and userspace utils could be eventually transformed to pure zig with no release interruption, no world-breaking forks. One day, release notes would simply state "... C support is now deprecated. OS/product X builds with zig, by default.", bootloader to kernel to userspace.
    Even if Rust can do all of the above -- if zig is just more natural to use for C programmers, it might have a very good chance.

  • @stupidburp
    @stupidburp 22 วันที่ผ่านมา

    I would like to see an updated presentation reflecting the current status of Zig. It looks like quite a bit has changed in the last 5 years.

  • @Megalcristo2
    @Megalcristo2 2 หลายเดือนก่อน

    13:17 In C++ functions are not constexpr by default for a reason: it is very easy to make unnoticed breaking changes if you don't promise that your function is constexpr explicitly. What if someone use your function result to create an array, but in some version you change the body?, same behavior, but now your function it can't be evaluated in constant time anymore, and you didn't even notice

  • @andrewrobinson2985
    @andrewrobinson2985 3 ปีที่แล้ว +21

    I've been following a language for some time now called V and it was a cool little project for awhile. It was tiny, had decent C interop, and was geared toward addressing problems with some modern programming languages. And it was simple. You could learn the language in a couple of days.
    I took a break from programming for a few months and I updated it and it's a mess. 7:38 really speaks to that - it's trying to be everything to everyone. It wants to be low-level and very memory safe, meanwhile its own stdlib has cross-platform window handling and opengl included natively.
    Excited to check zig out, I'm happy for it's uncompromising nature.

    • @TheMrKeksLp
      @TheMrKeksLp 2 ปีที่แล้ว +9

      Just FYI, V is pretty much a confirmed scam/vaporware at this point

    • @Mankepanke
      @Mankepanke 2 ปีที่แล้ว +2

      @@TheMrKeksLp I would like to know more about this. Is the somewhere I can read about this?

    • @tech6hutch
      @tech6hutch 11 หลายเดือนก่อน

      @@TheMrKeksLpif it’s the language I’m thinking of, they basically made claims about their memory model (guaranteed memory safety with neither a GC nor a borrow checker) that would have been impossible to fulfill without magic.

  • @diegosorte
    @diegosorte 2 ปีที่แล้ว +24

    I come from time to time to this talk to remind myself how awesome is zig. Now I’m even using it at my work :)

  • @suvetar
    @suvetar 15 วันที่ผ่านมา

    Mindblowingly good - I actually applauded the TH-cam video!

  • @PhilmannDark
    @PhilmannDark 3 ปีที่แล้ว +7

    Re defer and errdefer: Is it possible to mark a type as "resource" so you get a compile error when you forget to call defer or errdefer and just return from the code that creates it WITHOUT giving the resource to anyone?

    • @josh_flash
      @josh_flash 2 ปีที่แล้ว +1

      I like this idea a lot! I don't know whether it fits into the Zig ethos of simplicity, but it's certainly worth an RFC. If I had to guess, it'd probably be relegated to "user-land" to write an IDE tool. But even that would be super handy. Little IDE warnings when structs that have destroy/close/release methods do not call them in the same scope. I like it.

  • @NicolaLarosa
    @NicolaLarosa 3 ปีที่แล้ว +10

    40:21 "It all comes together in this vortex of synergy" Oh my gosh, I just can't handle this. :-D

  • @rcousens1982
    @rcousens1982 5 ปีที่แล้ว +27

    Great talk, Andrew!

  • @OpenGL4ever
    @OpenGL4ever 4 หลายเดือนก่อน

    How is this better?
    17:48 If I understand this correctly, this code seems to be executed at runtime to determine the operating system. At least in this IF block there is no comptime keyword that indicates otherwise. So if this is evaluated at runtime, this would have the advantage that the binary could run anywhere, but it also comes at the cost of making the binary larger. And if this occurs in time-critical places, it will be slower than a solution where the code is simply replaced by platform-specific code at compile time using a preprocessor, as in C.

    • @clang8649
      @clang8649 3 หลายเดือนก่อน

      "If the condition of an if statement is compile-time known, then the branches that are dead are eliminated statically"
      Because the value of builtin.os is known at compile time, the if statement is implicitly executed at compile time as well. Because the Zig compiler uses lazy evaluation impossible branches do not emit any code, because the compiler never analyses them.
      That's why the @compileError in the else branch is not emitted. The compiler can prove that the OS the binary is compiled for is always supported, so @compileError is never executed at compile time.

    • @OpenGL4ever
      @OpenGL4ever 3 หลายเดือนก่อน

      @@clang8649 Thank you for your clarification.

  • @krumbergify
    @krumbergify 3 ปีที่แล้ว +9

    Herb Sutter confirmed in a recent Cppcon talk that thrown C++ exceptions allocate memory on almost every platform, so you can't use them to catch a bad alloc, at least not if you are very close to the memory limit.

    • @Knirin
      @Knirin 2 ปีที่แล้ว +1

      My understanding is that exceptions require memory allocation by the spec.

    • @krumbergify
      @krumbergify 2 ปีที่แล้ว +1

      @@Knirin Well you could pass them back on the stack like Rust does with Result, but that would increase the stack size and break the ABI. There is no free lunch…

  • @yash1152
    @yash1152 ปีที่แล้ว

    28:31 stack trace & error trace..
    it would have been good to see this in the stderr output itself

    • @yash1152
      @yash1152 ปีที่แล้ว

      30:46 forced nullability
      i need to read why that is bad? i just barely know about NPE, but not its implications

  • @germandiagogomez
    @germandiagogomez 4 ปีที่แล้ว +17

    I am a C++ user and sometimes I miss this simplicity like Zig. On the other side, part of that complexity is also useful. I am with an eye on Rust, D, Nim and Zig lately. But for now, I stick to C++ and C#. I like to get the job done so anything that is not viable to finish full software is discarded directly on my side.

    • @rustmc
      @rustmc 3 ปีที่แล้ว +22

      yep, I always think of Rust as "the better C++", while Zig is "the better C". i personally really love both, but of course theres nothing wrong with sticking to C or C++ as long as they work out for you

    • @tomweh3710
      @tomweh3710 3 ปีที่แล้ว +4

      @@rustmc i am really excited about zig, but if you want to get the job done rust has already great support for many libraries, you can definitly write production code with it.

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว

      I've been using D many years ago. Even made a small project at work using it. But I've dropped it. D is kind of stagnating and what's worse - it doesn't introduce any new ideas.

    • @peezieforestem5078
      @peezieforestem5078 2 ปีที่แล้ว +1

      Also, check out Odin and Jai, 2 very promising systems programming languages.

  • @videojeroki
    @videojeroki 4 ปีที่แล้ว +58

    Much more readable than Rust.

    • @awwastor
      @awwastor 3 ปีที่แล้ว +6

      It depends. If you’re a C programmer, than yes, the syntax of Zig is practically the same. But if you’re a modern C++ programmer and/or a ML programmer, then Rust’s syntax is much more readable. ReasonML and Rust are quite close when it comes to syntax.

    • @totheknee
      @totheknee 3 ปีที่แล้ว +14

      @@awwastor I came from C++ and Rust is pretty unreadable. For example: `Has => (1..=3).contains` This looks nothing like C++, nor anything intelligible.

    • @awwastor
      @awwastor 3 ปีที่แล้ว +5

      @@totheknee Yeah that’s true. That looks like ML or even python. I like the Rust syntax more tbh.. “Has => (1..=3).contains” In this case I’m guessing you mean pattern matching(in a macro or match), but then Has needs to be an enum value, and the (1..=3).contains would need to be an instruction, so contains(x) I guess. It seems pretty readable to me, though it is quite far away from C++. For me the most unreadable thing in rust are c-style casts (the “as” keyword).

  • @distrologic2925
    @distrologic2925 5 ปีที่แล้ว +47

    23:03 that was top quality programmer humor :D

    • @codeman99-dev
      @codeman99-dev 3 ปีที่แล้ว

      The one and only time the audience actually reacted (audibly) during the talk.

  • @hikerwolfspaine8200
    @hikerwolfspaine8200 4 ปีที่แล้ว +38

    This reminds me a lot of Jonathan Blow's JAI language. I'll be watching both with enthusiasm.

    • @gideonunger7284
      @gideonunger7284 4 ปีที่แล้ว +3

      I think aspects of it are inspired by jai. I think the github readme references it a few times^^

    • @digitalspecter
      @digitalspecter 3 ปีที่แล้ว +15

      I follow both too. One major difference is that I've been able to write programs in Zig and that gives it a big headstart in mindshare =)

    • @totheknee
      @totheknee 3 ปีที่แล้ว +3

      Same, but I'm starting to wonder if JAI is becoming too complex and Zig will now be the _de facto_ Better C.

    • @hikerwolfspaine8200
      @hikerwolfspaine8200 3 ปีที่แล้ว +2

      @@totheknee JAI will probably a decent C++ replacement, so I'm not to worried if it goes above and beyond the strict code zig has to take on C.

  • @Matlalcueitl
    @Matlalcueitl 4 ปีที่แล้ว +5

    @52:13 What happens on OOM in Rust? ;-)

    • @CzipperzIncorporated
      @CzipperzIncorporated 4 ปีที่แล้ว +3

      Panic/Crash?

    • @sergeifomin9901
      @sergeifomin9901 4 ปีที่แล้ว

      I am not an embedded dev, so could you explain to me what other options would be preferable?
      My thinking would be that as you can handle panicking, you can handle OOM just fine.

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว +1

      @@sergeifomin9901 In Rust, panics cannot be caught or handled. Only on thread boundary - so, you'd have to have a master thread that manages/restarts a child thread. It might not be doable on embedded. Check out Zig in Production by Jens Goldberg talk. Jens mentions that OOM is the primary reason he doesn't use Rust (aside from slow compilation of course).

  • @OpenGL4ever
    @OpenGL4ever 4 หลายเดือนก่อน

    45:56 It's a pity, that inline assembly is not allowed. I love assembly language. But i understand, why they do it. But I would still have preferred it if it were possible.

    • @clang8649
      @clang8649 3 หลายเดือนก่อน +1

      Inline assembly is allowed at runtime, only compile time evaluation disallows inline assembly.

  • @BlackCodeMath
    @BlackCodeMath 5 วันที่ผ่านมา

    Bro went hard in the paint with this presentation.

  • @bloody_albatross
    @bloody_albatross 5 ปีที่แล้ว +12

    Can I use zig to cross compile a simple command line C application on Linux for macOS? With mingw it is easily possible to cross compile on Linux for Windows, but targeting macOS is a different (and horrible) story.

    • @fernandomoreira9009
      @fernandomoreira9009 5 ปีที่แล้ว +5

      It can. Check this tweet from Andrew: twitter.com/andy_kelley/status/1043597913304260608

    • @AndrewKelley
      @AndrewKelley 5 ปีที่แล้ว +21

      yes

  • @nathanruben3372
    @nathanruben3372 ปีที่แล้ว

    Preprecessors sometimes usefull, you do not want linux branches active windows even if those branches are not executed. Those code sections are striphed off before compilation.

    • @edgeeffect
      @edgeeffect 11 หลายเดือนก่อน

      17:12

  • @paidapps733
    @paidapps733 3 หลายเดือนก่อน +1

    9:00
    Who says its "supposed to work"?
    globals are static.
    Define len in main.
    Or do you propose a different storage for file scope and if so, why?

  • @yash1152
    @yash1152 ปีที่แล้ว

    20:17 rust print formatting errors....

    • @yash1152
      @yash1152 ปีที่แล้ว

      umh, but what does it mean for "language" to have it? like the fxn u're showing - aint that like compiler itself.... umh ohw wait, by language u mean the zig standard libs so to speak right?

  • @Vogel42
    @Vogel42 2 ปีที่แล้ว +2

    40:55 there should have been a standing ovation instead of a cough

  • @LarsBjerregaard
    @LarsBjerregaard 2 ปีที่แล้ว +1

    Great stuff! I really like the look and syntax and the build system seems awesome.

  • @IceGuye
    @IceGuye วันที่ผ่านมา

    "Let's fix the problem" The slideshow software got instantly frozen. lol

  • @bloody_albatross
    @bloody_albatross 4 ปีที่แล้ว +6

    I got my hopes up to be able to cross compile C code from Linux to macOS using Zig: The only other desktop OS I can cross compile to is Windows (with GNU libc).

  • @yash1152
    @yash1152 ปีที่แล้ว

    26:02 ohw, so, this is similar to "import std as std" in python right?
    "const std = @import("std");"

  • @diegosandoval2043
    @diegosandoval2043 5 ปีที่แล้ว +5

    How necessary is the Zig package manager? Can I have a project on an air-gapped computer just getting all the packages through a USB drive?

    • @blarghblargh
      @blarghblargh 5 ปีที่แล้ว +9

      The zig package manager doesn't exist currently. Pretty sure a tarball would work for copying deps

    • @dalecarnegie4440
      @dalecarnegie4440 3 ปีที่แล้ว

      The package manager is just a convenience. You can simply copy-paste deps to your project and it will work.

  • @zweiwing4435
    @zweiwing4435 ปีที่แล้ว

    I wish to buy the book?

  • @zdnui45jbsodfteu66
    @zdnui45jbsodfteu66 4 ปีที่แล้ว +4

    34:35 not so fast, where is checking for close errors?
    "A careful programmer will check the return value of close(), since it
    is quite possible that errors on a previous write(2) operation are
    reported only on the final close() that releases the open file
    description. Failing to check the return value when closing a file
    may lead to silent loss of data. "

    • @balen7555
      @balen7555 4 ปีที่แล้ว +5

      std.os.close does not return any errors in zig because what are you going to do with it? Obviously not retry close(2). An application which wants to ensure writes have succeeded before closing must call fsync before close.
      "A careful programmer who wants to know about I/O errors may precede
      close() with a call to fsync(2)."

    • @AndrewKelley
      @AndrewKelley 4 ปีที่แล้ว +5

      That's the documentation for libc close. The close OS syscall does not have the possibility of failure. That's something libc introduced into the equation. With Zig you are not forced to use libc.

    • @rt1517
      @rt1517 3 ปีที่แล้ว

      @@AndrewKelley
      Linux source is obviously available online.
      In include/linux/syscalls.h, we can see:
      asmlinkage long sys_close(unsigned int fd);
      In fs/file.c we can see that close syscall calls close_fd function.
      And we can see that close_fd can return -EBADF then calls filp_close from fs/open.c which tries to flush and may also return other error codes.
      By the way there is the "same" issue in Rust standard library (fd.rs): close call result is ignored. And it is not an oversight: this is by design. "drop" must not fail, just like C++ destructors must not fail either. For me that is a major flaw of RAII.
      In C you can try to write perfect error handling (checking results of close, CloseHandle, HeapFree...) with a bunch of gotos.
      I guess in Zig deferred code is not supposed to fail (return an error code)?

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว +1

      @@rt1517 Just tried it. And yes, "try" is not allowed inside defer expression.

  • @OpenGL4ever
    @OpenGL4ever 4 หลายเดือนก่อน

    Not good:
    13:44 So i can use this function during compile time and get for example a result, that is very hardware specific. I could for example use my MAC of my network card. Then i compile the code, create a binary and sent it to my friend and there the software will fail, because my MAC isn't identical with his MAC.

  • @conundrum2u
    @conundrum2u 7 หลายเดือนก่อน

    "why can't it *just* be this way" well you see.... there's over 40 years of history behind that reason and many architectures in-between. I look forward to new programming languages in 20 years where a young language designer goes "why didn't they *just* do it this way in the 2020's??!?!?!?" Zig is interesting. We'll see how it goes.

  • @polyhistorphilomath
    @polyhistorphilomath 3 ปีที่แล้ว +1

    Was it moved for great justice though?

  • @yash1152
    @yash1152 ปีที่แล้ว

    1:32 so the slide was really stuck lol!!

  • @Verrisin
    @Verrisin 3 ปีที่แล้ว +23

    Zig vs Rust? My understnading:
    Rust is to replace C++
    Zig is to replace C

    • @stupidburp
      @stupidburp 22 วันที่ผ่านมา

      Mojo is to replace Python

  • @paidapps733
    @paidapps733 3 หลายเดือนก่อน

    9:36
    "accidental variable length array"
    ??
    It's statically allocated using buffer_len.
    No buffer overflow happening there at all.

    • @Cloudef
      @Cloudef หลายเดือนก่อน

      Variable length array means array that gets allocated dynamically runtime. They usually have bad codegen as well, so you want to avoid them.

  • @higor129
    @higor129 5 ปีที่แล้ว +8

    IME any IDE with clang-based code model will work flawlessly when you use macros. Some even support displaying the post processed text on mouse over.

    • @nxxxxzn
      @nxxxxzn 4 ปีที่แล้ว

      *Qt Creator* does that, what other IDEs do you know?

    • @higor129
      @higor129 4 ปีที่แล้ว

      @@nxxxxzn I believe Clion and KDevelop (with the clang plugin enabled) support it too but I'm a QtCreator user myself.

  • @origamibulldoser1618
    @origamibulldoser1618 3 ปีที่แล้ว +2

    Does RAII serve the same purpose as errdefer? And if so, why was a new concept and/or nomenclature introduced? If not, what's the difference?

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว +5

      But Zig doesn't have RAII. defer is for cleanup on both success and error. And errdefer is for cleanup only on error.

    • @drygordspellweaver8761
      @drygordspellweaver8761 2 ปีที่แล้ว +1

      RAII eats up valuable CPU cycles for things you don’t need to have babysat

    • @origamibulldoser1618
      @origamibulldoser1618 2 ปีที่แล้ว

      @@drygordspellweaver8761 a trivial destructor will most likely not even be called. So What remains is work you want to do. Like free().

    • @drygordspellweaver8761
      @drygordspellweaver8761 2 ปีที่แล้ว

      ​@@origamibulldoser1618 that still leads to heap fragmentation which causes even more cpu slowdown. babysitting / garbage collection is never a good idea for serious software where performance is concerned

    • @origamibulldoser1618
      @origamibulldoser1618 2 ปีที่แล้ว

      @@drygordspellweaver8761 how does a function call affect memory layout?

  • @kenn850
    @kenn850 4 ปีที่แล้ว +1

    at 5:08 what about webassembly.

    • @digitalspecter
      @digitalspecter 3 ปีที่แล้ว +4

      I don't think anyone writes programs in straight webassembly =)

  • @germandiagogomez
    @germandiagogomez 4 ปีที่แล้ว +7

    I would reformulate "the simple, lazy way to write code must perform robust error handling". Robust error handling is a difficult problem. I would reformulate it as "the simple, lazy way to write code must fail safely or handle the error but never ignore it". I think this is a better way of looking at it. Imagine I want to create a piece of software, it reads from disk, does some operations and on the way to that it must read data (could fail), parse it (could be incorrect). If I need robust handling for each step, now I have a program where I have to write the code and the failure handlers, both. But I could be interested in just handling happy path (assume that if the reading fails or the parsing fails just finish the program, but without ignoring the error silently). Doing so would save time, because now I do not need to think of the error handling but I am still sure that it will fail safely. Later, if I ever need, I can add more robust error handling. This robust error handling can be as complicated as the program itself almost: ignore parse error vs no parse error, ignoring parse situation is safe vs is not safe... if the error for parsing makes the whole thing lose information or can be reconstructed from some redundant info... as you can see this is as complicated or more than writing the happy path maybe. So all in all, the important thing is that errors are not ignorable. This is a good property of exceptions, even if exceptions are not a panacea.

    • @johnbotris8187
      @johnbotris8187 3 ปีที่แล้ว +3

      thats exactly what try and ! are for though. just write the happy path and let the calling context handle it. they basically behave the same as exceptions but you target the specific calls that trigger them, rather than the standard try block which has so much room for misuse and abuse

    • @chrimony
      @chrimony 2 ปีที่แล้ว +2

      @@johnbotris8187 The happy path would not be putting "try" and "!" everywhere when you use the happy path. It's pointless clutter because when it comes to things like out of memory errors, you aren't going to handle it down in the bowels of your code. So all you're code is going to end up putting these useless decorations until you get to a top level error handler. This is what Java did by default, and it's wrong.

  • @mycollegeshirt
    @mycollegeshirt 2 ปีที่แล้ว +8

    I think it's that we can be bad at what we do. You don't have to be particularly smart to be a programmer, in other branches of engineering if your product isn't designed really well it usually fails, ours it's okay if it fails so long as it works a good majority of the time, most of our stuff is not at all well designed, due to business constraints, and really blind leading the blind tbh.

  • @Nathankthanks
    @Nathankthanks 4 ปีที่แล้ว +2

    11:56 seems to work fine in C. I guess the screenshot is for a particular version of GCC? seems to undermine the point though.

    • @tenv
      @tenv 3 ปีที่แล้ว

      I tried it out on my setup. It worked with Clang, but not with GCC.
      GNU gcc (GCC) 10.2.0
      clang version 11.1.0

  • @ciCCapROSTi
    @ciCCapROSTi 9 หลายเดือนก่อน

    I really want to know what Zig brings to the table over a feature-restricted C++. You can do most, if not all of these things in C++, and you don't HAVE TO use the nasty stuff.

  • @yash1152
    @yash1152 ปีที่แล้ว

    36:35 who, WHO said msvc 12GiB download is easier to install??????

  • @rasbinthapa5535
    @rasbinthapa5535 ปีที่แล้ว

    Please make documentation easy to read

  • @bloody_albatross
    @bloody_albatross 4 ปีที่แล้ว

    25:00 isn't that a leaking file descriptor? Ok, its the main function, so it doesn't matter, but if it wouldn't be and if write would fail it would return an error and not close the file.

    • @OMGclueless
      @OMGclueless 4 ปีที่แล้ว +1

      Yep. Andrew may not like the complexity of C++ but one of things it does right is make this particular error hard to write.

    • @0LoneTech
      @0LoneTech 4 ปีที่แล้ว +2

      Yes, but it could be fixed by moving the close up and deferring it, like destroy at 31:15.

  • @totheknee
    @totheknee 3 ปีที่แล้ว +1

    19:22 - How is that not known at compile-time? It's a string literal, right? Is that not stored as a static value at compile-time?

    • @crasyguy74.63
      @crasyguy74.63 3 ปีที่แล้ว +2

      its in a function that takes a noncomptine string thus it is not compile time known

  • @bloody_albatross
    @bloody_albatross 5 ปีที่แล้ว +1

    Does zig handle `#pragma pack` in C headers correctly?

    • @AndrewKelley
      @AndrewKelley 5 ปีที่แล้ว +12

      Looks like that's a TODO:
      github.com/ziglang/zig/blob/057a5d4898f70c6a8169c99375fbb8631e539051/src/translate_c.cpp#L4365
      Just a matter of figuring out the libclang API and setting is_packed to true on the AST node.

    • @drygordspellweaver8761
      @drygordspellweaver8761 2 ปีที่แล้ว

      @Andrew Kelley Hey Andrew - is it possible to remove the const and fn keywords? I’m lazy and want to type as little as humanly possible

  • @NikolajLepka
    @NikolajLepka 3 ปีที่แล้ว +5

    the need for defer could be mitigated entirely via RAII semantics and just have the handle close itself when it leaves a block

    • @mido3ds
      @mido3ds 3 ปีที่แล้ว +10

      Which needs objects which introduces complexities and implicit behaviour
      Explicit is better than implicit, it makes you reason about code easily
      Also, defer works best with c code
      Also, defer makes the code linear, you don't introduce a wrapping around an object to provide a destructor, you just call existing c init function and just call its free in the next line. Much simpler, you know there is destruction without looking around the code for destructor you didn't notice for each object you meet

  • @vasudevram
    @vasudevram 3 ปีที่แล้ว +2

    Why most Lisps? Why not all Lisps? If most Lisps, which are not crossed out? Lisp newbie here.

  • @rodelias9378
    @rodelias9378 3 ปีที่แล้ว +8

    Awesome work Andrew. Keep going!! 👍🏻👏🏻

  • @laughingvampire7555
    @laughingvampire7555 ปีที่แล้ว

    so if it isn't safe then it has no quality.

  • @abainbridge2005
    @abainbridge2005 5 ปีที่แล้ว +7

    On the "Why doesn't this work" slide (12m00s into the video), isn't the solution in C to use "enum { buffer_len = 100 };"? I like the Zig approach, but I think this example might need revisiting.

    • @JesseMeyer
      @JesseMeyer 4 ปีที่แล้ว +24

      That's a workaround demonstrating the problem.

  • @arborealanole7908
    @arborealanole7908 3 ปีที่แล้ว +2

    Move Zig. For great justice.

  • @bruxis
    @bruxis 4 ปีที่แล้ว +8

    Awesome talk Andrew, sorry the audience was full of wet napkins...

  • @IntrovertedTechie
    @IntrovertedTechie 2 ปีที่แล้ว +1

    12:48 you got me there

  • @alainterieur5004
    @alainterieur5004 4 ปีที่แล้ว +1

    very amazing

  • @adanjsuarez
    @adanjsuarez 10 หลายเดือนก่อน

    Zig is a monster!... in a very good way.

  • @lamebubblesflysohigh
    @lamebubblesflysohigh 3 ปีที่แล้ว +1

    Ok I thought I would be able to comprehend because I did some stuff in python... nah... if my brain had a compiler, it would self destruct

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว +2

      This is what I hate about programming. You have to compile and execute code in your head every time you have to read it.

  • @milahu
    @milahu 2 ปีที่แล้ว +1

    14:30 the need for comptime is surprising, as fibonacci(7) is a perfectly constant expression

    • @aasquared8191
      @aasquared8191 ปีที่แล้ว +1

      there's difference between "const" and "comptime const"

  • @nikolaikalashnikov4253
    @nikolaikalashnikov4253 5 ปีที่แล้ว +4

    7:19 Eventually, someone is going to download the source-code off github & start adding C++ features to Zig and it'll become a Zig++ monstrosity like C++.
    Instead, he should put these extra features in the Zig++ spec, but that doesn't mean he has to implement them... Instead, if he gets ahead & the game & takes control of the software specification for Zig++ then he can at least hopefully prevent some of the insanity that found it's way into C++ while also making Zig & Zig++ 100% compatible.

    • @kayomn
      @kayomn 4 ปีที่แล้ว +4

      people are free to do what they will
      does not mean he should be the one to do it

    • @balen7555
      @balen7555 4 ปีที่แล้ว +3

      C++ back then added so much onto C that it made a lot of sense for people to use it instead of C. I am pretty sure that if someone were to create "zig++", when there's no reason to and nobody probably ever will, it will just die silently with nobody using it. It's really rare for PL authors to resist the temptation of adding new cool features but Andrew Kelley is doing an amazing job at this. Zig might be aimed to be a better C but it doesn't need to have as low of productivity as C; it's 2020 ffs.

    • @_myron
      @_myron 4 ปีที่แล้ว +6

      I'm already doing that. I called it ZigZag

    • @drygordspellweaver8761
      @drygordspellweaver8761 2 ปีที่แล้ว +1

      C++ didn’t add any new features to C- only complexity then endless ways to work around the complexity they themselves introduced.

  • @conceptualprogress
    @conceptualprogress 3 ปีที่แล้ว +2

    So basicaly now we can have runtime errors at compile time 0.0

  • @michadarowny3811
    @michadarowny3811 2 ปีที่แล้ว

    Feel in love, just wow

  • @ninjaaron
    @ninjaaron 4 หลายเดือนก่อน

    12:58 TFW the creator of a language you're interested casually puts "hail Satan" in the middle of his talk and you're trying to decide if it's a joke or a dog whistle.

    • @blarghblargh
      @blarghblargh หลายเดือนก่อน

      who cares and why

  • @zungaloca
    @zungaloca 4 ปีที่แล้ว +1

    really good

  • @zytr0x108
    @zytr0x108 ปีที่แล้ว +4

    What I don’t understand is if he just wanted it to be C with improvements, why did he change the syntax so drastically? It’s quite an adjustment to write
    var name: type = value
    Instead of
    type name = value
    I’m sure it has a reason, maybe to make it easier to differentiate functions and variables? But he didn’t really talk about it.

    • @josealonso7321
      @josealonso7321 2 หลายเดือนก่อน

      I think it has to do with type inference. Java did the same few years ago.

  • @ws9691
    @ws9691 5 หลายเดือนก่อน +1

    "Better Than C" - Nope! Looking at Zig's hodgepodge of weird backwards syntax - no thanks. Pretty much what you would expect from a satanist @12:57

    • @leeroyjenkins0
      @leeroyjenkins0 5 หลายเดือนก่อน +1

      Hail Satan

    • @happygofishing
      @happygofishing 4 หลายเดือนก่อน

      @@leeroyjenkins0 cringe.

    • @blarghblargh
      @blarghblargh หลายเดือนก่อน

      use python. it sounds like about all you can handle

  • @qm3ster
    @qm3ster ปีที่แล้ว +1

    Oh no, prefix "try" :(

  • @Kabodanki
    @Kabodanki ปีที่แล้ว

    there's code in airplane and elevator though, why won't it work for voting ? that's dumb

  • @zungaloca
    @zungaloca 3 ปีที่แล้ว

    Amazing

  • @Ltuhkeeo
    @Ltuhkeeo 3 ปีที่แล้ว

    what do you think of rust?

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว

      Did you watch the video? He said he loves Rust.

  • @zungaloca
    @zungaloca 4 ปีที่แล้ว

    amazing

  • @AbhimanyuAryan
    @AbhimanyuAryan 3 ปีที่แล้ว +1

    Zig for C devs

  • @zxnnightstalker2289
    @zxnnightstalker2289 ปีที่แล้ว +1

    Wow, I got an idea. Let's do Zig++

  • @paidapps733
    @paidapps733 3 หลายเดือนก่อน

    10:16
    No, you don't (need a preprocessor directive).
    You've allready demonstrated that though while going on about a non existant buffer overflow.

  • @firsttyrell6484
    @firsttyrell6484 5 ปีที่แล้ว +11

    I like the language, but the name of it is a bit unfortunate. As a citizen of East European country I can't help but remember a certain greeting where the first word sounds like Zig and the second word sounds like Heil.

    • @baxiry.
      @baxiry. 5 ปีที่แล้ว +2

      yes, In Morocco: Zig: means fraud and deception

    • @0LoneTech
      @0LoneTech 4 ปีที่แล้ว +11

      That's spelled sieg, and IMHO taboos shouldn't live forever. Some appropriations are better reversed.

    • @Dennis-nx8gj
      @Dennis-nx8gj 3 ปีที่แล้ว +2

      Sieg (victory) would be a cool connotation. It triumphs over inferior languages :D

    • @etodemerzel2627
      @etodemerzel2627 3 ปีที่แล้ว +1

      That's my number 2 issue with the language. Number 1 was already fixed on the master branch.

  • @bobweiram6321
    @bobweiram6321 3 ปีที่แล้ว +5

    This looks like a hacked up version of rust.

  • @igorsilva736
    @igorsilva736 3 ปีที่แล้ว

    47:08

  • @laughingvampire7555
    @laughingvampire7555 ปีที่แล้ว

    3:17 given that the most used programming languages in the industry are garbage collected, even for HFT like Java/C# and for the web are still Java/C#/PHP/Python/Ruby the title of that slide is a little too wrong. Those languages are widely used, and they were designed for those specific use-cases because no one wants to invent a hammer to nail everything including screws, remember "right tool for the job"
    And docker yes, I agree that was the case, at least in part, but mostly was about ensuring that also testing and the execution of the applications was reproducible because most programming languages with a few exceptions like anything that runs on the jvm, clr, beam or anything that uses memimage-based development ala smalltalk/common-lisp suck at isolation from the OS because the most popular languages like php, ruby, python, c, perl are tightly integrated into Linux.
    with anything that runs on the jvm/clr/beam you can easily distribute a precompiled signed package to deploy it easily. it can be compiled easily anywhere as long as it remains in this curated environment easily because all you need is the SDK of each of them. With memimage/beam is even easier because you don't even have to restart the environments.
    the problem and the culprits are the shitty php/python/perl/ruby/nodejs

  •  3 ปีที่แล้ว

    1:03 "We can do better than this". Some seconds later...

  • @brentmifsud6181
    @brentmifsud6181 ปีที่แล้ว +1

    one of the biggest issues I have working with C is that its just not human readable.
    Compare that with something like swift where code reads out like English sentences.

  • @Flishman
    @Flishman 2 ปีที่แล้ว +1

    😁when your app is lower than c, someone will rewrite it. hahah

  • @sirgalahamtroskipero4872
    @sirgalahamtroskipero4872 3 ปีที่แล้ว +4

    Another Esperanto of programming language?

  • @iarde3422
    @iarde3422 2 ปีที่แล้ว +1

    "Perl applications are not going to do advantage of a python library...", that's a false statement!
    There is a module in perl, allowing to use an inline python in perl code and use python libraries.
    In addition, there are many other interesting modules in perl, like allowing inline and library C, ASM, TCL and some others.

  • @AyrtonGomesz
    @AyrtonGomesz ปีที่แล้ว

    Tough crowd haha