The Road to Zig 1.0 - Andrew Kelley

  Рет қаралды 138,796

ChariotSolutions

ChariotSolutions

Күн бұрын

Пікірлер
@DanielSantaCruz
@DanielSantaCruz 3 жыл бұрын
"C was broken, and I fixed it" -- haha, love it.
@skaruts
@skaruts 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@bogdanpanchuk296 I don't think you understand what analogies are.
@bogdanpanchuk296
@bogdanpanchuk296 3 жыл бұрын
@@fennecbesixdouze1794 "we need MORE layers of the abstraction" etc.
@monsterhunter445
@monsterhunter445 2 жыл бұрын
"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 жыл бұрын
@@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 4 жыл бұрын
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 жыл бұрын
I agree
@TheSulross
@TheSulross 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 Жыл бұрын
Are you really not a tech guy? You are watching a video that programmers don't even watch or get to know.
@jstenberg3192
@jstenberg3192 Жыл бұрын
@@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 9 ай бұрын
@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 жыл бұрын
I think he makes a lot of good points and I use C a lot.
@joshuaclayton6940
@joshuaclayton6940 8 ай бұрын
I love the involuntary case study of the slideshow breaking just as Andrew was making a joke about software being broken.
@michaelharrington6698
@michaelharrington6698 2 жыл бұрын
The native printf language support with the comptime support then showing how comptime supports generics was awesome. Nicely done!
@Russtopia
@Russtopia 5 жыл бұрын
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.
@alainterieur5004
@alainterieur5004 4 жыл бұрын
I think it has a non-LLVM backend now
@DelgardAlven
@DelgardAlven 2 жыл бұрын
deep sh*t. like.
@AnonEMoose-mr8jm
@AnonEMoose-mr8jm 5 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
@@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 2 жыл бұрын
You predicted the future ;) we now have Bun in the javascript world.
@opensourcedev22
@opensourcedev22 Жыл бұрын
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
@mullergyula4174
@mullergyula4174 2 жыл бұрын
I love your approach. Rust sounds like something that can get very complicated.
@diegosorte
@diegosorte 2 жыл бұрын
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 :)
@edgeeffect
@edgeeffect 11 ай бұрын
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 жыл бұрын
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 жыл бұрын
Just FYI, V is pretty much a confirmed scam/vaporware at this point
@Mankepanke
@Mankepanke 2 жыл бұрын
@@TheMrKeksLp I would like to know more about this. Is the somewhere I can read about this?
@tech6hutch
@tech6hutch Жыл бұрын
@@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 жыл бұрын
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 жыл бұрын
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.
@NicolaLarosa
@NicolaLarosa 3 жыл бұрын
40:21 "It all comes together in this vortex of synergy" Oh my gosh, I just can't handle this. :-D
@FostersLagerMorphs
@FostersLagerMorphs Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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.
@rcousens1982
@rcousens1982 5 жыл бұрын
Great talk, Andrew!
@eigentensor
@eigentensor Жыл бұрын
This is probably the single best talk I've ever seen, bravo
@hikerwolfspaine8200
@hikerwolfspaine8200 4 жыл бұрын
This reminds me a lot of Jonathan Blow's JAI language. I'll be watching both with enthusiasm.
@gideonunger7284
@gideonunger7284 4 жыл бұрын
I think aspects of it are inspired by jai. I think the github readme references it a few times^^
@digitalspecter
@digitalspecter 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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.
@germandiagogomez
@germandiagogomez 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
Also, check out Odin and Jai, 2 very promising systems programming languages.
@Megalcristo2
@Megalcristo2 3 ай бұрын
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
@stupidburp
@stupidburp Ай бұрын
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.
@suvetar
@suvetar Ай бұрын
Mindblowingly good - I actually applauded the KZbin video!
@krumbergify
@krumbergify 3 жыл бұрын
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 жыл бұрын
My understanding is that exceptions require memory allocation by the spec.
@krumbergify
@krumbergify 2 жыл бұрын
@@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…
@aftalavera
@aftalavera 5 күн бұрын
Another shiny thing! Nobody notice the syntax? So perfect!
@videojeroki
@videojeroki 4 жыл бұрын
Much more readable than Rust.
@awwastor
@awwastor 3 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
@@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 жыл бұрын
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.
@PhilmannDark
@PhilmannDark 3 жыл бұрын
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 жыл бұрын
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.
@LarsBjerregaard
@LarsBjerregaard 2 жыл бұрын
Great stuff! I really like the look and syntax and the build system seems awesome.
@higor129
@higor129 5 жыл бұрын
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.
@Verrisin
@Verrisin 3 жыл бұрын
Zig vs Rust? My understnading: Rust is to replace C++ Zig is to replace C
@stupidburp
@stupidburp Ай бұрын
Mojo is to replace Python
@BlackCodeMath
@BlackCodeMath 23 күн бұрын
Bro went hard in the paint with this presentation.
@rodelias9378
@rodelias9378 3 жыл бұрын
Awesome work Andrew. Keep going!! 👍🏻👏🏻
@mycollegeshirt
@mycollegeshirt 2 жыл бұрын
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.
@OpenGL4ever
@OpenGL4ever 5 ай бұрын
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 4 ай бұрын
"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 4 ай бұрын
@@clang8649 Thank you for your clarification.
@Vogel42
@Vogel42 2 жыл бұрын
40:55 there should have been a standing ovation instead of a cough
@bloody_albatross
@bloody_albatross 5 жыл бұрын
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 жыл бұрын
It can. Check this tweet from Andrew: twitter.com/andy_kelley/status/1043597913304260608
@AndrewKelley
@AndrewKelley 5 жыл бұрын
yes
@bloody_albatross
@bloody_albatross 4 жыл бұрын
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).
@OpenGL4ever
@OpenGL4ever 5 ай бұрын
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 4 ай бұрын
Inline assembly is allowed at runtime, only compile time evaluation disallows inline assembly.
@conundrum2u
@conundrum2u 8 ай бұрын
"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.
@zdnui45jbsodfteu66
@zdnui45jbsodfteu66 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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@rt1517 Just tried it. And yes, "try" is not allowed inside defer expression.
@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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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.
@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
@yash1152
@yash1152 Жыл бұрын
26:02 ohw, so, this is similar to "import std as std" in python right? "const std = @import("std");"
@OpenGL4ever
@OpenGL4ever 5 ай бұрын
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.
@paidapps733
@paidapps733 4 ай бұрын
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?
@Nathankthanks
@Nathankthanks 4 жыл бұрын
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
@NikolajLepka
@NikolajLepka 3 жыл бұрын
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 жыл бұрын
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
@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.
@Matlalcueitl
@Matlalcueitl 4 жыл бұрын
@52:13 What happens on OOM in Rust? ;-)
@CzipperzIncorporated
@CzipperzIncorporated 4 жыл бұрын
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 жыл бұрын
@@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).
@IceGuye
@IceGuye 20 күн бұрын
"Let's fix the problem" The slideshow software got instantly frozen. lol
@yash1152
@yash1152 Жыл бұрын
1:32 so the slide was really stuck lol!!
@diegosandoval2043
@diegosandoval2043 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 жыл бұрын
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.
@khoaphananhtran362
@khoaphananhtran362 3 күн бұрын
The error handling should be explicit
@khoaphananhtran362
@khoaphananhtran362 3 күн бұрын
My bad for not watching till the end. Error handling is actually ok 👌
@polyhistorphilomath
@polyhistorphilomath 3 жыл бұрын
Was it moved for great justice though?
@yash1152
@yash1152 Жыл бұрын
36:35 who, WHO said msvc 12GiB download is easier to install??????
@bruxis
@bruxis 4 жыл бұрын
Awesome talk Andrew, sorry the audience was full of wet napkins...
@totheknee
@totheknee 3 жыл бұрын
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 жыл бұрын
its in a function that takes a noncomptine string thus it is not compile time known
@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 жыл бұрын
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 жыл бұрын
Yes, but it could be fixed by moving the close up and deferring it, like destroy at 31:15.
@rasbinthapa5535
@rasbinthapa5535 Жыл бұрын
Please make documentation easy to read
@zweiwing4435
@zweiwing4435 Жыл бұрын
I wish to buy the book?
@vasudevram
@vasudevram 3 жыл бұрын
Why most Lisps? Why not all Lisps? If most Lisps, which are not crossed out? Lisp newbie here.
@arborealanole7908
@arborealanole7908 3 жыл бұрын
Move Zig. For great justice.
@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?
@abainbridge2005
@abainbridge2005 5 жыл бұрын
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 жыл бұрын
That's a workaround demonstrating the problem.
@paidapps733
@paidapps733 4 ай бұрын
9:36 "accidental variable length array" ?? It's statically allocated using buffer_len. No buffer overflow happening there at all.
@Cloudef
@Cloudef 2 ай бұрын
Variable length array means array that gets allocated dynamically runtime. They usually have bad codegen as well, so you want to avoid them.
@IntrovertedTechie
@IntrovertedTechie 2 жыл бұрын
12:48 you got me there
@milahu
@milahu 2 жыл бұрын
14:30 the need for comptime is surprising, as fibonacci(7) is a perfectly constant expression
@aasquared8191
@aasquared8191 Жыл бұрын
there's difference between "const" and "comptime const"
@nikolaikalashnikov4253
@nikolaikalashnikov4253 5 жыл бұрын
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 жыл бұрын
people are free to do what they will does not mean he should be the one to do it
@balen7555
@balen7555 4 жыл бұрын
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 жыл бұрын
I'm already doing that. I called it ZigZag
@drygordspellweaver8761
@drygordspellweaver8761 2 жыл бұрын
C++ didn’t add any new features to C- only complexity then endless ways to work around the complexity they themselves introduced.
@alainterieur5004
@alainterieur5004 4 жыл бұрын
very amazing
@lamebubblesflysohigh
@lamebubblesflysohigh 3 жыл бұрын
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 жыл бұрын
This is what I hate about programming. You have to compile and execute code in your head every time you have to read it.
@origamibulldoser1618
@origamibulldoser1618 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
at 5:08 what about webassembly.
@digitalspecter
@digitalspecter 3 жыл бұрын
I don't think anyone writes programs in straight webassembly =)
@raconvid6521
@raconvid6521 9 күн бұрын
If you mean Web Assembly Text, then it’s amazing in my opinion. It is a lot more like C or Lisp.
@laughingvampire7555
@laughingvampire7555 Жыл бұрын
so if it isn't safe then it has no quality.
@conceptualprogress
@conceptualprogress 3 жыл бұрын
So basicaly now we can have runtime errors at compile time 0.0
@etodemerzel2627
@etodemerzel2627 3 жыл бұрын
Lol, that's awesome.
@sirgalahamtroskipero4872
@sirgalahamtroskipero4872 3 жыл бұрын
Another Esperanto of programming language?
@firsttyrell6484
@firsttyrell6484 5 жыл бұрын
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 жыл бұрын
yes, In Morocco: Zig: means fraud and deception
@0LoneTech
@0LoneTech 4 жыл бұрын
That's spelled sieg, and IMHO taboos shouldn't live forever. Some appropriations are better reversed.
@Dennis-nx8gj
@Dennis-nx8gj 3 жыл бұрын
Sieg (victory) would be a cool connotation. It triumphs over inferior languages :D
@etodemerzel2627
@etodemerzel2627 3 жыл бұрын
That's my number 2 issue with the language. Number 1 was already fixed on the master branch.
@bloody_albatross
@bloody_albatross 5 жыл бұрын
Does zig handle `#pragma pack` in C headers correctly?
@AndrewKelley
@AndrewKelley 5 жыл бұрын
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
@zungaloca
@zungaloca 4 жыл бұрын
really good
@michadarowny3811
@michadarowny3811 2 жыл бұрын
Feel in love, just wow
@brentmifsud6181
@brentmifsud6181 Жыл бұрын
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.
@Kabodanki
@Kabodanki Жыл бұрын
there's code in airplane and elevator though, why won't it work for voting ? that's dumb
@adanjsuarez
@adanjsuarez 11 ай бұрын
Zig is a monster!... in a very good way.
@zytr0x108
@zytr0x108 Жыл бұрын
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 3 ай бұрын
I think it has to do with type inference. Java did the same few years ago.
@qm3ster
@qm3ster Жыл бұрын
Oh no, prefix "try" :(
@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
@elmar64
@elmar64 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.
@bobweiram6321
@bobweiram6321 3 жыл бұрын
This looks like a hacked up version of rust.
@AbhimanyuAryan
@AbhimanyuAryan 3 жыл бұрын
Zig for C devs
@zxnnightstalker2289
@zxnnightstalker2289 Жыл бұрын
Wow, I got an idea. Let's do Zig++
@HairyPixels
@HairyPixels Жыл бұрын
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 Жыл бұрын
Because C syntax is ugly compare to Zig. Zig has a python-like and readable syntax.
@HairyPixels
@HairyPixels Жыл бұрын
@@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 Жыл бұрын
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 11 ай бұрын
​@@sarfaraz73​ Disagree, I'm checking this Zig language out and I don't like the syntax at all, specially arrays.
@happygofishing
@happygofishing 5 ай бұрын
C has some bad syntax too, like switch statements.
@zungaloca
@zungaloca 4 жыл бұрын
amazing
@zungaloca
@zungaloca 3 жыл бұрын
Amazing
@lodgin
@lodgin 3 жыл бұрын
The fact that it uses TypeScript's method of defining types for parameters and variables, but NOT for functions is making me irrationally angry
@ninjaaron
@ninjaaron 5 ай бұрын
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 2 ай бұрын
who cares and why
@paidapps733
@paidapps733 4 ай бұрын
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.
@jackshen1028
@jackshen1028 3 жыл бұрын
very like a rustified Ada,i think zig should keep borrow more from Ada like contract
@Flishman
@Flishman 2 жыл бұрын
😁when your app is lower than c, someone will rewrite it. hahah
Intro to the Zig Programming Language • Andrew Kelley • GOTO 2022
50:14
Rust: A Language for the Next 40 Years - Carol Nichols
55:08
ChariotSolutions
Рет қаралды 360 М.
Caleb Pressley Shows TSA How It’s Done
0:28
Barstool Sports
Рет қаралды 60 МЛН
Война Семей - ВСЕ СЕРИИ, 1 сезон (серии 1-20)
7:40:31
Семейные Сериалы
Рет қаралды 1,6 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 155 М.
The Return of Procedural Programming - Richard Feldman
52:53
ChariotSolutions
Рет қаралды 61 М.
What's a Memory Allocator Anyway? - Benjamin Feng
48:30
Zig SHOWTIME
Рет қаралды 60 М.
They Made a Sequel to C
1:53:24
Tsoding Daily
Рет қаралды 112 М.
Programming in C3 to Annoy Zig fans
1:51:55
Tsoding Daily
Рет қаралды 55 М.
Interview with Zig language creator Andrew Kelley
17:30
Context Free
Рет қаралды 47 М.
Caleb Pressley Shows TSA How It’s Done
0:28
Barstool Sports
Рет қаралды 60 МЛН