129 points · by tosh · 5mo ago · 63 comments
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.
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.
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.
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.
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?
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.
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".
* 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.
This is a very good ability to have in an application like a database.
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).
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.
> - rewordings
> - "memory is a resource" goes without saying
> - emphasize the final point
wow, what a self report
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.
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.