4 ms·
An example of Zig not having generics, interfaces, and macros? I don't understand.
by pron 1y ago
An example of Zig not having generics, interfaces, and macros? I don't understand.
- danielEM 1y ago@pron If all you mean is there is more syntax to D than to zig to achieve same/similar thing then you may be a bit aggresive on how you communicate it.
- pron 1y agoIt's not about more syntax, it's about design, and how Zig was the first to use partial evaluation to do away with several, rather common, features. It's like how the novelty of the iPhone's touchscreen design was in not having a keypad, or that the novelty of the spork wasn't in inventing the functionality of either the spoon or the fork, but in having a single utensil that performs both. The more important aspect isn't the functionality but the design. I'm not saying you need to like any of these designs, but they are novel. Saying that you could have a similar functionality by other means misses the point as much as saying that there's nothing special about a spork because if you have a spoon and a fork, then you have the same functionality. But you still don't have a spork. You could, then, ask what the point of the novel design is. Well, in some languages you have generics and interfaces and compile-time expressions, but because none of these is general and powerful enough, so you also have macros. Macros are very powerful - perhaps too powerful - but they are difficult to understand, so they're used sparingly even if they can subsume other functionality. Zig has shown that you can do almost anything you would reasonably want to do with macros with partial evaluation that has access to reflection. That wasn't obvious at all. And because that feature was not only powerful enough to subsume other features and make them redundant, but also very simple and easy to understand, it ended up with a design that is both minimal and easy to read (which is important for code reviews) but also highly expressive. Again, you don't have to like this rather minimalistic design, but it is novel.
- WalterBright 1y ago> Zig was the first to use partial evaluation to do away with several, rather common, features Please show an example of Zig partial evaluation.
- pron 1y agoI posted a few examples below: https://news.ycombinator.com/item?id=45865028 https://news.ycombinator.com/item?id=45865028
- WalterBright 1y agoThe partial evaluation you mentioned.
- pron 1y agoI'm still not sure what exactly you're asking, but the implementation of print linked above (https://ziglang.org/documentation/0.15.2/#Case-Study-print-in-Zig https://ziglang.org/documentation/0.15.2/#Case-Study-print-i...) typically requires some kind of syntactic macros in other lanugages as does something like "innerParse" here (https://ziglang.org/documentation/0.11.0/std/src/std/json/static.zig.html#L64 https://ziglang.org/documentation/0.11.0/std/src/std/json/st...), this (https://ziglang.org/documentation/0.15.2/#Generic-Data-Structures https://ziglang.org/documentation/0.15.2/#Generic-Data-Struc...) would typically require some kind of a separate generics or templates feature in other languages, and to see how comptime replaces interfaces, search for "formatType" here: https://marcelgarus.dev/comptime https://marcelgarus.dev/comptime. Again, the novel use of partial evaluation in Zig is that it eliminates generics, interfaces, and macros. Any language that has one or more of these features does not have this novel design.
- WalterBright 1y agoprint is a fairly complicated case, as it has to deal with all kinds of different types. I mean a simple example. Just to illustrate the concept. Like the examples I provided here: https://news.ycombinator.com/item?id=45859669 https://news.ycombinator.com/item?id=45859669
- pron 1y agoIf you scroll a bit up on the page from the print example, you'll see more introductory stuff: https://ziglang.org/documentation/0.15.2/#Introducing-the-Compile-Time-Concept https://ziglang.org/documentation/0.15.2/#Introducing-the-Co...