3 ms·
> If you run tests on a Zig program out of the box you won't have array overflows; that's not what you get in C and C++. Build a C program in the right mode (a
by Rusky 7y ago
> If you run tests on a Zig program out of the box you won't have array overflows; that's not what you get in C and C++.
Build a C program in the right mode (also required for Zig) and you get exactly the same thing.
- pron 7y agoWhat mode would that be? The various fsanitize options? C doesn't have slices. Zig also allows turning on safety on a scope level. Not to mention the powerful comptime polymorphism/introspection mechanism that allows working in a more typesafe manner than C, while still being much simpler than Rust.
- Rusky 7y agoI don't see how Zig comptime is any simpler than Rust. Frankly, it seems more of a kluge. But we've already been over this before. :)
- pron 7y agoA single construct does the work, or most of the work, of generics, value generics, const fn, traits, attributes (although I expect some form of attributes might be added to Zig) and macros, and it does so without type-level programming or macro-level programming, both their own mini-languages. A kludge is in the eye of the beholder, but one is simpler than five or six.
- zozbot234 7y agoRust has procedural macros too. And they're not a separate "mini-language" like the C++ template hacks, they just use Rust itself, except with a phase separation involved since they run at compile time.
- pjmlp 7y agoIn C++17 and moreso in C++20, doing C++ template hacks is only excusable for legacy code, or trying to make code portable to older compilers.
- pron 7y agoThis is worse. Feature-rich languages like C++ and Rust always end up adopting pretty much every nice feature from every other language. The trick is to have fewer features, not more; at least that's my aesthetic preference. In other words, brag about the features you don't have, not the features you do :)
- jeltz 7y agoAs someone who is using procedural macros in my crates: they are nowhere close to as powerful yet as Zig's compile time evaluation. For example they cannot be used in expressions in stable Rust without ugly hacks yet, and the tools for generating the new AST are quite clunky and hard to write fast code for.
- Rusky 7y agoThat's hardly an honest comparison. I can just as easily split comptime into "type comptime," "value comptime," "comptime blocks," "builtin functions like @isInteger," and "inline control structures" (that one doesn't even use the "comptime" name!). Arguably this combination is more complex than Rust's. It has no way to constrain a comptime type argument (traits), so you get error messages like C++ templates. It has no way to constrain a function to be comptime-compatible (const fn), so you get more error messages like C++ templates. When you want to combine things, you manage phase ordering and idioms by hand, basically re-implementing Rust-like concepts at every use site. Sometimes one or two more concepts in the language makes things simpler. To use a subject you've discussed before, it's similar to scoped continuations vs full call/cc.
- pron 7y ago> I can just as easily split comptime into In Rust, generics, macros, traits, compile-time evaluation are different constructs with drastically different syntax (and generics and value generics are different features, implemented at different times, but I can accept them as a single construct). > It has no way to constrain a comptime type argument (traits) It does: introspection, just as Clojure can constrain arguments, only Zig does it at compile time. > so you get error messages like C++ templates You don't because in C++ templates are programmed in their own sub-language with SFINAE tricks (at least in the C++ versions I use; they've probably added new ways to do this, as they do). In Zig, it's just Zig computation. You'd get similar compile-time errors as you would get, at runtime, in, say, Clojure or Python. > When you want to combine things, you manage phase ordering and idioms by hand, basically re-implementing Rust-like concepts at every use site. You don't need to reimplement things by hand at every use site; you just call a subroutine at compile time. > Sometimes one or two more concepts in the language makes things simpler. I agree, but I think that Zig's comptime brings revolutionary simplicity to the very complex subject of partial evaluation which is so important in systems languages. How well it would work in practice remains to be seen, and I may well be disappointed, but I find Zig's approach of simplicity first very appealing. I agree it's a matter of taste.
- Rusky 7y ago