The Road to Zig 1.0 - Andrew Kelley

Поділитися
Вставка
  • Опубліковано 18 чер 2024
  • Despite being one of the youngest programming languages, Zig is progressing rapidly toward its first production-ready release. Join creator Andrew Kelley for a justification of Zig’s existence and a tour of the unique features of Zig. See what people have already built with it today, and explore what will be possible when Zig reaches 1.0. Bring your skepticism, tough questions, and unusual use cases.
    Philly ETE 2019 Playlist: • Philly ETE 2019
    On the Chariot Solutions site: chariotsolutions.com/screencasts/
  • Наука та технологія

КОМЕНТАРІ • 337

  • @DanielSantaCruz
    @DanielSantaCruz 2 роки тому +43

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

  • @skaruts
    @skaruts 3 роки тому +201

    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 2 роки тому +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 2 роки тому +5

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

    • @bogdanpanchuk296
      @bogdanpanchuk296 2 роки тому +10

      @@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 роки тому +4

      @@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.

  • @connorm9176
    @connorm9176 3 роки тому +234

    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 2 роки тому +16

      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 Рік тому

      frfr really excited

    • @drygordspellweaver8761
      @drygordspellweaver8761 Рік тому

      Wish they would drop the const keyword though

    • @origamibulldoser1618
      @origamibulldoser1618 Рік тому

      @@drygordspellweaver8761 mutability is important.

  • @joshuaclayton6940
    @joshuaclayton6940 Місяць тому +4

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

  • @opensourcedev22
    @opensourcedev22 9 місяців тому +8

    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

  • @jstenberg3192
    @jstenberg3192 Рік тому +24

    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 Рік тому +14

      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 9 місяців тому +1

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

    • @jstenberg3192
      @jstenberg3192 9 місяців тому +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 9 місяців тому

      @@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 2 місяці тому

      @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.

  • @SourceCodeDeleted
    @SourceCodeDeleted 4 роки тому +83

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

  • @Russtopia
    @Russtopia 5 років тому +134

    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.

  • @michaelharrington6698
    @michaelharrington6698 Рік тому +16

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

  • @AnonEMoose-mr8jm
    @AnonEMoose-mr8jm 5 років тому +100

    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 2 роки тому +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 2 роки тому +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 Рік тому +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 Рік тому +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.

  • @diegosorte
    @diegosorte 2 роки тому +20

    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 :)

  • @mullergyula4174
    @mullergyula4174 2 роки тому +13

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

  • @eigentensor
    @eigentensor Рік тому +1

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

  • @rcousens1982
    @rcousens1982 5 років тому +27

    Great talk, Andrew!

  • @LarsBjerregaard
    @LarsBjerregaard 2 роки тому +1

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

  • @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

  • @leontepe2329
    @leontepe2329 2 роки тому +4

    This is amazing.

  • @edgeeffect
    @edgeeffect 4 місяці тому +1

    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.

  • @andrewrobinson2985
    @andrewrobinson2985 3 роки тому +20

    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 роки тому +7

      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 5 місяців тому

      @@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.

  • @enverhoxha2698
    @enverhoxha2698 4 роки тому +25

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

    • @mgord9518
      @mgord9518 Рік тому +4

      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.

  • @rodelias9378
    @rodelias9378 3 роки тому +8

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

  • @FostersLagerMorphs
    @FostersLagerMorphs 10 місяців тому +2

    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 8 місяців тому +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 7 місяців тому +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.

  • @distrologic2925
    @distrologic2925 4 роки тому +47

    23:03 that was top quality programmer humor :D

    • @codeman99-dev
      @codeman99-dev 2 роки тому

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

  • @hikerwolfspaine8200
    @hikerwolfspaine8200 3 роки тому +38

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

    • @gideonunger7284
      @gideonunger7284 3 роки тому +3

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

    • @digitalspecter
      @digitalspecter 3 роки тому +14

      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.

  • @alainterieur5004
    @alainterieur5004 4 роки тому +1

    very amazing

  • @videojeroki
    @videojeroki 3 роки тому +53

    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 роки тому +11

      @@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).

  • @zungaloca
    @zungaloca 3 роки тому +1

    really good

  • @zungaloca
    @zungaloca 3 роки тому

    Amazing

  • @Verrisin
    @Verrisin 2 роки тому +22

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

  • @blenderpanzi
    @blenderpanzi 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).

  • @zungaloca
    @zungaloca 3 роки тому

    amazing

  • @conundrum2u
    @conundrum2u Місяць тому

    "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.

  • @krumbergify
    @krumbergify 2 роки тому +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 Рік тому +1

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

    • @krumbergify
      @krumbergify Рік тому +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…

  • @michadarowny3811
    @michadarowny3811 2 роки тому

    Feel in love, just wow

  • @germandiagogomez
    @germandiagogomez 3 роки тому +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 роки тому +21

      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 2 роки тому

      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 Рік тому +1

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

  • @PhilmannDark
    @PhilmannDark 2 роки тому +6

    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 Рік тому +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.

  • @IntrovertedTechie
    @IntrovertedTechie Рік тому +1

    12:48 you got me there

  • @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.

  • @higor129
    @higor129 4 роки тому +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.

  • @yash1152
    @yash1152 10 місяців тому

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

    • @yash1152
      @yash1152 10 місяців тому

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

  • @polyhistorphilomath
    @polyhistorphilomath 2 роки тому +1

    Was it moved for great justice though?

  • @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.

  • @Vogel42
    @Vogel42 Рік тому +1

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

  • @adanjsuarez
    @adanjsuarez 4 місяці тому

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

  • @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?

  • @yash1152
    @yash1152 10 місяців тому

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

  • @blenderpanzi
    @blenderpanzi 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

  • @arborealanole7908
    @arborealanole7908 2 роки тому +2

    Move Zig. For great justice.

  • @Nathankthanks
    @Nathankthanks 3 роки тому +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 3 місяці тому

    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.

  • @germandiagogomez
    @germandiagogomez 3 роки тому +6

    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.

  • @yash1152
    @yash1152 10 місяців тому

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

  • @blenderpanzi
    @blenderpanzi 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 3 роки тому +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 3 роки тому +2

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

  • @blenderpanzi
    @blenderpanzi 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 Рік тому

      @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

  • @abhishekpandework4461
    @abhishekpandework4461 2 роки тому

    WTF!! Eye opener!

  • @Matlalcueitl
    @Matlalcueitl 4 роки тому +5

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

    • @CzipperzIncorporated
      @CzipperzIncorporated 4 роки тому +3

      Panic/Crash?

    • @sergeifomin9901
      @sergeifomin9901 3 роки тому

      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 2 роки тому +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).

  • @kenn850
    @kenn850 3 роки тому +1

    at 5:08 what about webassembly.

    • @digitalspecter
      @digitalspecter 3 роки тому +4

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

  • @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 2 роки тому +2

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

  • @bruxis
    @bruxis 4 роки тому +7

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

  • @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 2 роки тому +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.

  • @rasbinthapa5535
    @rasbinthapa5535 11 місяців тому

    Please make documentation easy to read

  • @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 2 роки тому +9

      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

  • @AbhimanyuAryan
    @AbhimanyuAryan 2 роки тому +1

    Zig for C devs

  • @origamibulldoser1618
    @origamibulldoser1618 2 роки тому +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 2 роки тому +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 Рік тому +1

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

    • @origamibulldoser1618
      @origamibulldoser1618 Рік тому

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

    • @drygordspellweaver8761
      @drygordspellweaver8761 Рік тому

      ​@@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 Рік тому

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

  • @vasudevram
    @vasudevram 3 роки тому +2

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

  • @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"

  • @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 3 роки тому +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 2 роки тому +1

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

  • @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.

  • @laughingvampire7555
    @laughingvampire7555 11 місяців тому

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

  • @yash1152
    @yash1152 10 місяців тому

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

  • @yash1152
    @yash1152 10 місяців тому

    20:17 rust print formatting errors....

    • @yash1152
      @yash1152 10 місяців тому

      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?

  • @nikolaikalashnikov4253
    @nikolaikalashnikov4253 4 роки тому +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 Рік тому +1

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

  •  3 роки тому

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

  • @igorsilva736
    @igorsilva736 3 роки тому

    47:08

  • @Hadi-hf3oe
    @Hadi-hf3oe 4 роки тому +4

    عالی

  • @bobweiram6321
    @bobweiram6321 2 роки тому +5

    This looks like a hacked up version of rust.

  • @EzequielRegaldo
    @EzequielRegaldo Рік тому

    With composition and functional std lib like golang + http standard servers this lang will rock

  • @qm3ster
    @qm3ster Рік тому +1

    Oh no, prefix "try" :(

  • @AyrtonGomesz
    @AyrtonGomesz 11 місяців тому

    Tough crowd haha

  • @Flishman
    @Flishman Рік тому +1

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

  • @conceptualprogress
    @conceptualprogress 2 роки тому +2

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

  • @Ltuhkeeo
    @Ltuhkeeo 2 роки тому

    what do you think of rust?

    • @etodemerzel2627
      @etodemerzel2627 2 роки тому

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

  • @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.

  • @SimGunther
    @SimGunther 3 роки тому +4

    0:49 Aged like milk

    • @digitalspecter
      @digitalspecter 3 роки тому +2

      How so? It's still terrifying :D

    • @SianaGearz
      @SianaGearz 2 роки тому +1

      I don't think so. Have you ever seen a software engineer say "fully digital voting is great, we don't need a hardcopy paper trail or an independent verification method; let's put all our eggs in one basket, the technology is guaranteed perfect and can't possibly go wrong or be manipulated invisibly."
      Circumstances can demand compromises, that we can agree to begrudgingly.

  • @zxnnightstalker2289
    @zxnnightstalker2289 Рік тому +1

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

  • @laughingvampire7555
    @laughingvampire7555 11 місяців тому

    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

  • @Kabodanki
    @Kabodanki Рік тому

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

  • @Morphinwithyou
    @Morphinwithyou Рік тому

    I liked the idea but Syntax is not good.

  • @HairyPixels
    @HairyPixels Рік тому +1

    He's fixing C, great, but then why scramble all the syntax? It would have been far more useful to the rest of the world if he maintained as much of the C syntax as possible.

    • @sarfaraz73
      @sarfaraz73 11 місяців тому +1

      Because C syntax is ugly compare to Zig. Zig has a python-like and readable syntax.

    • @HairyPixels
      @HairyPixels 11 місяців тому

      @@sarfaraz73 That's all subjective. I'm not a c programmer but I'd be curious if they think C is ugly and what parts they want changed on average.

    • @parkerhuntington1360
      @parkerhuntington1360 8 місяців тому

      I am not an expert by any means, but from what I understand C (and especially C++) are deceptively complicated to parse. For example, in c a function call can be ambiguous with a variable declaration. So when you parse C you need to do a certain amount of semantic analysis at the same time. While this won't be a bottle neck when creating release builds, frontend performance is more important for debug builds and language servers. This can be mitigated by incremental compilation, but the complexity trade off is steep because now the compiler is a function of the current source and previous collateral. Eli Bendersky has several interesting blog posts talking about some of the complexities in parsing c and c++ if you are interested.
      Zig also lacks multiline comments (and has a unique multiline string syntax) so that each line can be tokenized individually. This means that syntax highlighting in a text editor only needs to be concerned with the lines on the screen. By contrast, in c the multiline comments mean that you must always scan up the file to see if you are in a comment or not. This can cause performance issues in editors when working on large files, so some tools limit the length that will be scanned, but this can cause desyncs where it inverts what should be a comment. @@HairyPixels

    • @sergiorodrigoroyo5079
      @sergiorodrigoroyo5079 5 місяців тому

      ​@@sarfaraz73​ Disagree, I'm checking this Zig language out and I don't like the syntax at all, specially arrays.

  • @jackshen1028
    @jackshen1028 3 роки тому +2

    very like a rustified Ada,i think zig should keep borrow more from Ada like contract

  • @ukyoize
    @ukyoize 4 роки тому +1

    I have a sinister feeling that i will just put a lot of catch do_nothing();

    • @erikengheim1106
      @erikengheim1106 3 роки тому +4

      You just put `try` in front of the statement that can produce an error. Then it will automatically return from the function with the error code. That is an ultra simple way of propagating errors, up the call stack.

  • @sirgalahamtroskipero4872
    @sirgalahamtroskipero4872 3 роки тому +4

    Another Esperanto of programming language?

  • @DSBrekus
    @DSBrekus 3 роки тому +1

    You lost me at "promote code reuse".

  • @firsttyrell6484
    @firsttyrell6484 4 роки тому +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. 4 роки тому +2

      yes, In Morocco: Zig: means fraud and deception

    • @0LoneTech
      @0LoneTech 3 роки тому +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 2 роки тому +1

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

  • @elmar64
    @elmar64 2 роки тому +3

    C's biggest problems are the lack of abstraction or standard library which makes it unproductive to use and the absense of any safety.
    Zig addresses safety but other languages do as well like Rust, Ada, Nim. C++ does not address safety and also lacks powerful language abstractions. It just has verbose syntax and complicated rules.
    I only watched this video but I don't see a unique solution which D or Nim wouldn't have.
    * compile-time constants are "enum" in D
    * conditional compilation has "version", "debug" or "static if" in D.
    * "comptime" is "static" or "enum" in D. But explicit compile-time code makes code harder to maintain. It typically leads to "brain methods". However, Zig's solution is admittedly simpler, particularly simpler than explicit "template" concepts.
    * "comptime" arguments are template parameters (with complicated type system they can become dangerous for productivity very fast).
    * stack traces are pretty standard.
    * "defer" and "errdefer" is like "scope(exit)" and "scope(failure)" in D. Nim's lead programmer almost wanted to kill this feature from Nim. Fortunately not.
    * switch in the catch-clause looks like "final switch" in D
    * own build system.
    * D features an own C compiler which doesn't support VLAs however.
    Error handling problems apparently not solved: separating responsibilities. Error handling should be separated from the correct paths but cramming them in the same function makes it hard to maintain and read.
    The real future would be productive safety: code synthesis (automatic code generation from specifications) and verification features like using ghost variable information at runtime and solver-aided programming abstracted via language concepts for very simple use. That's a point where D won't have success.
    Another thing: Powerful iterator abstraction instead of pointers. Automatically generate optimal iteration code based on where the abstraction is used without using indices or other meaningless helper variables.
    I'd like to see clever aspect-oriented features to separate code and data structures into separate parts which can be combined automatically. Uninspired pesky tasks like transforming data structures and complex values into reordered or subset data structures should be auto-generated code. Physical structure of objects could be abstracted away completely, be interchangeable and only needs to be explicit for interfacing with foreign languages / machines.

  • @death-disco
    @death-disco 4 роки тому +6

    Programming language popularity list is missing Rust, which is voted #1 on many lists including stackoverflow

    • @SMOKE3104
      @SMOKE3104 4 роки тому +4

      It wouldn't help his argument.

    • @shelammustafa692
      @shelammustafa692 3 роки тому +11

      Correction: #1 loved on stackoverflow. likability != popularity.

    • @etodemerzel2627
      @etodemerzel2627 2 роки тому +7

      He said TIOBE list. Rust is only number 24 there (as of August 2021).

    • @Beefster09
      @Beefster09 2 роки тому +2

      we'll see how long that lasts when zig compiles several orders of magnitude faster. 15 minute compile times are a hefty price to pay for the borrow checker.

    • @death-disco
      @death-disco 2 роки тому

      @@Beefster09 if compile time was the only metric for a language go use c89.

  • @divianschwitzle846
    @divianschwitzle846 2 роки тому

    What about Rust?

  • @krystofjakubek9376
    @krystofjakubek9376 3 роки тому +1

    To me it seems like he is reinventing the wheel a bit. I 100% agree with the premise and the build tools part is great but many of the other problems were already solved in C++.
    For compile time keyword you have constexpr, Assertions can be done at compile time, for cleanup code you have RAII and a lot more. Now with C++ 20 you can use the new import keyword to fix the #include fiesta. Dont get me wrong I do not think in no way that this is bad or worse than C++ but I am not sure if it is revolutionary enough to bring in enough people.

    • @neoillogic
      @neoillogic 3 роки тому +8

      I don't think he intend his project to be revolutionary. He is cutting part bad parts of C and adding a small set of old good ideas to make a "better C". It is simple and fast to learn, and way simpler to use and avoid UB while generating fast binaries. As an "occasional" C++ dev and I like it way better than C++ or C. So I intend to use Zig or Rust, depending on the complexity of the project, whenever native code is required, and the JVM for everything else as usually. There are a few projects where unfortunately I will have to keep using C++, and C++20 is not an option for these, huge codebases of old C++ code...

    • @etodemerzel2627
      @etodemerzel2627 2 роки тому +2

      "It's so frigging complicated. I can barely read my own C++ code, let alone my co-workers."

  • @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.