5 ms·
The energy in this project is amazing! The idea of including a C++ and a C compiler gratis is brilliant, and solves a big interoperability headache very elegan
by ncmncm 5y ago
The energy in this project is amazing!
The idea of including a C++ and a C compiler gratis is brilliant, and solves a big interoperability headache very elegantly.
For my own purposes, IIUIC it is fatally flawed, lacking destructors, but as a raw C replacement it has legs. Compile-time execution and types as regular compile-time values makes it actually powerful.
- pjmlp 5y ago> The idea of including a C++ and a C compiler gratis is brilliant, and solves a big interoperability headache very elegantly. C++ did it first, having been born at same place as UNIX and C, all major C compiler vendors quickly added it into the box.
- ncmncm 5y agoIt would be better if a C or C++ header sufficed to declare things so they may be called directly from Zig, without need for matching declarations in Zig. Or, do they? For it to be useful, types would need to be imported, too. That would need destructor and overloading support. Which is doable.
- pjmlp 5y agoDepends how much modern C and C++ Zig wants to implement in order to understand the types. Generics, lambdas, concepts, templates, exceptions, ....
- ncmncm 5y agoIf Zig doesn't have lambdas yet, that is a clear omission. It would be wise to reserve syntax for it early.
- somethingor 5y agoThat is how Zig works with C code: - https://ziglang.org/learn/overview/#integration-with-c-libraries-without-ffibindings https://ziglang.org/learn/overview/#integration-with-c-libra... - https://ziglang.org/documentation/master/#Import-from-C-Header-File https://ziglang.org/documentation/master/#Import-from-C-Head...
- ncmncm 5y agoOK, that is very cool. It makes Zig seem like a markedly better choice than Rust for adoption in Linux.
- dnautics 5y ago> lacking destructors seriously? write a `deinit(self: *Self)` function into your struct and explicitly call `defer obj.deinit()`. Explicit is better than implicit. And the penalty? One line of code per destroy site, plus writing the `allocator.destroy(self)` line in your deinit method. As a result of being explicit, SO many headaches are solved. What are the rules again when you have a C++ class that polymorphically inherits destruction? What were the override rules, if your child class needs to implement its destructor? What order do destructors trigger when there's more than one for stack-objects? what about in std::vector?? What about in std::map??
- slimsag 5y agoI think GP means RAII, which is still an open area of discussion in Zig: https://github.com/ziglang/zig/issues/782 https://github.com/ziglang/zig/issues/782 I'd love to see it if it can be implemented in a way that fits the language, but that remains to be seen.
- ncmncm 5y agoActually, no, I mean destructors. Equivalent to Rust's Drop trait. Those are needed for RAII, but also for about everything else. (You need other things, too, to make RAII.) They were the only thing that made C++ uniquely powerful in 1985, and the only reason Rust can begin to compete. They represent the first and still only piece of runtime automation seen anywhere in the programming world. (Some would claim GC, but it doesn't do anything.) Destructors are necessary for correct-by-construction coding. The only code you can be completely certain is correct is the code you didn't have to write. None of dnautics's questions ever arise. I don't have to think about them, and I can't get them wrong. If you imagine destructors have something to do with memory management, you have much yet to learn. Zig is doing almost everything right to become essential infrastructure, but will need to add some equivalent of destructors to get there.
- diragon 5y ago>The only code you can be completely certain is correct is the code you didn't have to write. This reminds me of Douglas Adams. "The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at and repair." This seems to be a matter of taste with no absolute conclusion to be reached which style is better. At least until we get significantly better at analysing codebases and software quality.