8 ms·
Zig (the language) is very appealing as a "better C than C". Check out https://ziglang.org https://ziglang.org (dis-disclaimer: I'm unaffiliated.)
by drfuchs 7y ago
Zig (the language) is very appealing as a "better C than C". Check out https://ziglang.org https://ziglang.org (dis-disclaimer: I'm unaffiliated.)
- ifreund 7y agoAye, and it lives up to that claim as well in my opinion, despite being still relatively young and pre-1.0. My favorite thing about Zig is that it has managed to stay simple and solve many of the problems of C without resorting to greatly increased complexity like Rust (which is much more of a C++ replacement than a C replacement in my opinion).
- d4mi3n 7y agoIMO the marketing as Rust as a C/C++ replacement is a bit misplaced. I think it's more accurate to consider it an alternative systems language. The tools/languages used in this space are a bit broader than C-family languages.
- ifreund 7y agoThat's true, though systems programming is in practice dominated by the C ABI (great post on that here by the way https://drewdevault.com/2020/03/03/Abiopause.html https://drewdevault.com/2020/03/03/Abiopause.html). Zig does something quite special that puts it ahead of the crowd in this space; It can import and use C libraries as easily as C does (no bindings required), and it can itself be built into a C library, auto-generating the required C headers.
- d4mi3n 7y agoYou are absolutely correct on the point of the C ABI. It's definitely the systems lingua franca. Just finished reading the Zig cc article and I must say I'm also quite impressed. I'll be keeping an eye on the next Zig release--being able to eventually use it as a `cc` or `mvsc` replacement would be a big game changer. Having recently run the study of trying to cross compile a few C++ and GTK apps, I can really see the appeal.
- stjohnswarts 7y agoI know it's not as complicated as C++ but it sure seems like they're in a rush to get there :) . Modern (post c++14) covers most of my criticisms of c++ for my daily driver. I still poke at Rust because I really love statically typed languages :)
- yarrel 7y agoI've been very surprised by Rust's complexity. Some of it seems to be being hidden over time (as well as adding new features) but its syntax at any given moment is generally more complex than C++.
- throwaway17_17 7y agoI’m not being contrarian, but I have only been following Zig in passing. Can you give a few example of the increase in complexity, I am genuinely curious. Zig seems, to my eyes at least, to have done an admirable job of remaining simple when compared to the behemoth that is C++, of any vintage (but especially post C++03).
- LessDmesg 7y agoRust is not a C++ replacement, nor a C replacement. It targets its own niche (embedded, realtime, correctness-oriented). It's a totally different development culture. Zig, OTOH, is absolutely a C replacement.
- otabdeveloper2 7y ago> It targets its own niche (embedded, realtime, correctness-oriented). I don't know of anyone who actually uses Rust in that niche. Everyone who uses Rust is using it because of "C++ is hard, let's go shopping instead" syndrome. I.e., at this point it's a language for beginners to ease themselves into programming without training wheels and eventually graduate to real big boy programming languages.
- smolder 7y agoThis is a strange sentiment. I think 99/100 people who know rust would not categorize it as "for beginners"
- otabdeveloper2 7y agoIt's pretty much irrelevant what people feel emotionally about Rust. The real-world fact is that Rust is, as of March 2020 at least, an entry-level systems programming language. It's used as a stepping stone by former PHP/Python/Go programmers, who are very intimidated by C++, to get into performance-oriented coding. Nobody actually writing embedded or sensitive code (airplanes, nuclear power stations, etc.) is doing it in Rust.
- dystroy 7y agoThis makes zero sense and it's not about emotion. The language is young and you don't certify a software solution every two days or don't rewrite your nuclear power station code every day. Very experienced programmers switched to Rust because it makes it possible to build large scale industrial programs both efficient and reliable. They won't switch to C++ just because they think they're good enough to live dangerously. (btw I work on plant control and yes I write parts in Rust)
- agapon 7y agoI don't know... To me, zig does not look like C at all. IMO, go and zig are as similar to each other as they are dissimilar to C.
- agapon 7y agoI mean, is this C-like? fn add(a: i32, b: i32) i32 { return a + b; }
- AndyKelley 7y agoYes: https://godbolt.org/z/72Dvpe https://godbolt.org/z/72Dvpe
- iruoy 7y agoSimple stuff like this looks very similar to Rust: https://godbolt.org/z/spkKai https://godbolt.org/z/spkKai Rust quickly becomes harder though, while Zig is much easier to grasp.
- tsimionescu 7y agoThe fact that they compile to the same assembly instruction does not make them similar source code.
- tzjmetron 7y agoSemantics vs syntax.
- abainbridge 7y agoThe languages are similar enough that the Zig tool-chain can translate C source into Zig source. There's mostly a one-to-one correspondence.
- tzjmetron 7y agoTo be fair, that's not really a very strong point, is it? Any language can be translated into C via an appropriate transpiler.
- jjnoakes 7y agoI wonder how much it would cost to sponsor compiles-via-c support. I'd love to use zig-the-language but I need to compile for platforms that LLVM does not support, so I would need to use the native C toolchain (assembler/linker at the least, but using the native C compiler seems easier).
- ihnorton 7y agoThere is a semi-maintained (perhaps more accurately “occasionally resurrected”) C backend for LLVM: https://github.com/JuliaComputing/llvm-cbe https://github.com/JuliaComputing/llvm-cbe
- jjnoakes 7y agoThanks; I was aware of this but last I checked it only supports a subset of LLVM (whatever Julia needed).
- ndesaulniers 7y ago> (dis-disclaimer: I'm unaffiliated.) https://ziglang.org/#Sponsors https://ziglang.org/#Sponsors > drfuchs oh, ok
- boltzmann_brain 7y agoOn a first glance, it does look like a simpler version of Rust, and I say it without demeaning Zig. Looks very promising, I'll be keeping an eye for it.
- pjmlp 7y agoI am still not sold on its security story, usage of @ and module imports.
- skrebbel 7y agoCan you elaborate on the security story story?
- pjmlp 7y agoManual memory management, we have already learned that isn't the way to go, when security is part of the requirements in a connected world. Still no way to catch use-after-free. https://github.com/ziglang/zig/issues/3180 https://github.com/ziglang/zig/issues/3180
- skrebbel 7y agoClear, good point, thanks.