Zig Zen Update
Posted by tosh 3 days ago
Comments
Comment by mcherm 3 days ago
I always felt that Python's "There should be one-- and preferably only one --obvious way to do it." was a bit of a mess.
Obviously (to anyone who was around at the time), that plank was written in response to Perl's motto: "There is more than one way to do it."
Zig's original take on this, "Only one obvious way to do things" seems even worse. You see, both languages agree that Perl had it wrong: it is unhelpful to have several different ways to write any future. But they went a little too far: it is not actually bad for it to be possible to write the same thing in more than one way.
Zig's new phrasing: "There is an idiomatic way to do it." captures the CORRECT alternative to Perl's motto. It is not important that there be no alternative ways of writing something, Rather, it is important that there be a single idiomatic way to write it.
Comment by brakl 3 days ago
Comment by Fraterkes 3 days ago
Also, importantly, the Zen of Python is kinda written as a set of ideas that Python should aspire to ("there should be one obvious way to do it") instead of a sales pitch of Python's merits. I prefer that.
Comment by iroddis 3 days ago
Comment by geophph 3 days ago
Comment by kgwxd 3 days ago
Comment by moron4hire 3 days ago
Comment by embedding-shape 3 days ago
Comment by Validark 3 days ago
Comment by Panzerschrek 3 days ago
Yes it can. But it's nearly impossible to handle such cases properly. That's why checking each allocation manually is a bad idea. Other languages do this better - they provide nice abstractions, but if something fails, the language runtime terminates the process. The result is the same, but has much less friction.
Also on some systems (like Linux) memory allocation may not fail, but the "allocated" memory may not be available and a program can crash accessing this memory.
Comment by lionkor 3 days ago
If you work in an environment where memory allocations can't fail or can't be handled if they fail, you might not want to use Zig, or C for that matter. Not every language should be designed to live in the space of "somehow low level but also a good choice for your basic web backend", like Rust.
Comment by kibwen 3 days ago
Comment by Zambyte 3 days ago
Comment by kibwen 3 days ago
Comment by Zambyte 3 days ago
And Zig does have language-level features that combine to require you to explicitly handle propagated errors (error sets, requiring all return values be explicitly handled, requiring all switch cases be explicitly handled). Rust has a similar set of features (pattern matching, requiring all match cases be explicitly handled), but does not use them for allocation (Box::new, vec![], etc. does not return a Result value).
Comment by kibwen 2 days ago
That's what Rust's libcore is for. And the converse is that if your software is written for a system with overcommit--so every typical OS and distro these days--any error path having to do with memory allocation failure is impossible to trigger, because the OS won't honestly tell you if allocation would fail.
> And Zig does have language-level features that combine to require you to explicitly handle propagated errors
Of course, and Zig also doesn't stop you from writing a data structure that papers over allocation failures by using `std.process.exit` in the error path. Zig also discourages third-party dependencies more than Rust does, so I wouldn't be surprised if people are already wisely doing this when writing their code for programs targeting systems with overcommit.
Comment by Panzerschrek 3 days ago
It's most of environments. Basically any program running under a modern OS. So, why do this language exists, if its practical applicability is so small?
Comment by Zambyte 3 days ago
Let's say you write an application that runs as a Unix daemon in Zig. Later you may decide that your application is really the only thing you're interested in running on the target machine, and for performance and predictability reasons, you'd prefer to boot directly to your application, instead of to an OS that launches your daemon. You can just swap out the implementation of the std.Io runtime for one that targets the hardware directly, instead of a Unix. You don't have to make any changes to your application.
That's kind of an extreme case, but it's the kind of flexibility Zig provides.
Comment by Panzerschrek 3 days ago
In my hypothetical example of a language where allocation fails aren't exposed it's possible too. An allocation fail just triggers a full system reboot.
Comment by lionkor 3 days ago
This language exists to supercede or supplement C, not JavaScript or C#.
It's practical applicability is similar to that of C, so I struggle to comprehend how it is "so small".
Comment by Panzerschrek 3 days ago
I can ignore errors, but I still need to free memory manually if I want to avoid memory leaks. Languages like C++ or Rust have destructors, which do the job for me.
> This language exists to supercede or supplement C
There are way better alternatives, like Rust. Even C++ is better.
Comment by lionkor 1 day ago
Comment by Panzerschrek 19 hours ago
Comment by audunw 2 days ago
Comment by Laremere 3 days ago
* There are many useful ways to handle it properly, and your choice depends on your program's constraints. The very small amount of friction (once you're used to it) encourages you to consider what ways to handle it are viable, such as allocating all memory at startup.
* If your strategy is to crash immediately, there is very little additional friction but you get the benefit of it being obvious in your code that this is the case.
* There are environments where memory allocation fails immediately, including if you turn off over-commit on Linux. If your hardware is dedicated to running a high reliability system, configuring it in this way is reasonable.
* Memory is not the only resource. Indeed, removing the special call out is what changed here. That different resources are handled with the same mechanism (errors, instead of eg returning null from malloc) is good.
Comment by Panzerschrek 3 days ago
Comment by ozgrakkurt 3 days ago
This is a very good ability to have in an application like a database.
Comment by Panzerschrek 3 days ago
Comment by ozgrakkurt 3 days ago
You also get locality benefits from bump style allocators. And you don't need SmallVec or similar optimization containers. And you also avoid mental overhead of managing many allocations in your head (or using a language with borrow checking).
Comment by Panzerschrek 3 days ago
Checking each Result in a large program is more complicated than having a runtime library handling memory limits properly.
> And you also avoid mental overhead of managing many allocations in your head
That's exactly what languages like Zig force you to do, compared to something like C++ or Rust.
> or using a language with borrow checking
borrow checking gives memory safety. It's also important to have.
Comment by underdeserver 3 days ago
There are many scenarios, especially in embedded systems, where it can happen and you want to handle it robustly, e.g. by evicting a cache or flushing a buffer to disk.
Comment by Panzerschrek 3 days ago
Comment by alberth 3 days ago
Comment by peesem 3 days ago
Comment by rowbin 3 days ago
Comment by dgellow 3 days ago
Comment by rowbin 3 days ago
Comment by dgellow 3 days ago
> - rewordings
> - "memory is a resource" goes without saying
> - emphasize the final point
Comment by frde_me 3 days ago
Comment by melon_tusk 3 days ago
Comment by norman784 3 days ago
Comment by jraph 3 days ago
Comment by jordand 3 days ago
Comment by dom96 3 days ago
Comment by IshKebab 3 days ago
Comment by kristoff_it 3 days ago
Comment by quarkz14 3 days ago
Comment by sgt 3 days ago
Comment by midnight_eclair 3 days ago
wow, what a self report
Comment by Yokohiii 3 days ago
Comparing Jai and Zig on that behalf is crazy.
Edit: If that is about political activism it's even more crazy. A dude that rambles about woke stuff is political as well. Maybe just aligns with yours.
Comment by ulbu 3 days ago
Comment by ksec 3 days ago
Like what? Plenty of people here follows Zig here and haven't seen any of it. And by any measure it is the least activism per language usage.
Comment by logicchains 3 days ago
Comment by Permik 3 days ago
Just the open amount of discontent towards the language and the community, creates the perfect storm for a malicious individual to pose being a Rust developer that sends death threats for doing things that are not aligned with the values of the language/community.
Comment by logicchains 3 days ago