7 ms·
What Is Zig's Comptime?
- saintfiends 7y agoInteresting. I would love to see a similar article on memory management in Zig.
- jorangreef 7y agoZig is worth supporting. Andrew Kelley, the author, was recently accepted into GitHub's Sponsors program. This means for every $1 you contribute, GitHub will match your donation for the first year: https://github.com/users/andrewrk/sponsorship https://github.com/users/andrewrk/sponsorship
- DJTtt 7y agoThat's interesting. Looks like it's a limited beta right now, I wonder if anyone will be able to enable Patreon-esque sponsorship for their projects in the future and what the requirements will be. Also very generous of Microsoft to match donations.
- hellcow 7y agoThere's nothing generous about it. Microsoft is well behind Patreon and this is a way to get creators to swap to using GitHub for donations.
- patrickmcnamara 7y agoIs there something to stop creators using both?
- hellcow 7y agoNot in theory, but in practice why would any creator encourage people to give them money on a platform that pays out half of the other one? They would push all people to the one with double payouts.
- saagarjha 7y agoWhat can Zig not do at compile time?
- pron 7y agoSee https://ziglang.org/documentation/master/#Compile-Time-Expressions https://ziglang.org/documentation/master/#Compile-Time-Expre...
- checktheorder 7y agoIt can't stop all your base from belong to us.
- mratsim 7y agoIt cannot do code generation.
- JBReefer 7y agoGood!
- Siyo 7y agoWhile comptime looks extremely powerful, I'm really not a fan of how it's used for unconstrained generics. This is the same problem I have with C++ templates where an incorrect use of a generic function would result in an explosion of bizarre undescriptive template errors. Sure you can write these type asserts yourself, but it's time consuming and how many developers will actually do it and get it right? I don't know, maybe it's really not that big of a deal, but I much prefer how Rust does this using traits as type constraints (although at some cost of complexity, e.g. Eq, PartialEq, Ord, PartialOrd). Not to mention that by using constraints on the type system level, you actually get useful type signature documentation on what you can or cannot pass to a function.
- moomin 7y agoThe presence of general type level programming does, however, mean that you can build decent preconditions on types. Which will get you further than you could in C++. I’m more concerned by the typeid switching, but maybe it’s got a proper structured mechanism as well.
- pjmlp 7y agoThat C++ problem is partially fixed via enable_if, static_assert and constexpr if. And fully fixed in future C++20 codebases with concepts.
- pron 7y agoFor one, Zig's error reporting is more friendly than C++ and will continue to get better. For another, it's a tradeoff, but the fact that the language is so much simpler than C++/Rust and compilation faster gives you a lot of headroom elsewhere (when the development cycle is faster, it's easier to focus your resources where they matter most to you). Of course, language preference is personal and aesthetic, and different people have different preferences.
- gnuvince 7y agoZig is a simpler language, but that simplicity comes at a cost: the memory bugs that exist in C also exist in Zig. Users bear the cost of the programmer using a simple language. Rust is a more complex language, but it eliminates a number of classes of memory error. In this case, the programmer bears the cost of users having safer programs. Although I find Zig very interesting—and I wish Andy the best of success with it—the trade-off that the Rust offers is more in line with my values and my ethics.
- andyonthewings 7y agoHaxe's macro is similar. It can run arbitrary code during compilation. One useful thing to do is to get the current git commit hash and inject it into the program: https://code.haxe.org/category/macros/add-git-commit-hash-in-build.html https://code.haxe.org/category/macros/add-git-commit-hash-in...
- hwj 7y agoConsidering that many compilers are written in the language they compile I was surprised by the Zig compiler being written in C++. Does anybody know the reason?
- euan_torano 7y agoThe stage 1 compiler is written in C++, but the Stage 2 compiler will be Zig: https://github.com/ziglang/zig#stage-2-build-self-hosted-zig-from-zig-source-code https://github.com/ziglang/zig#stage-2-build-self-hosted-zig... Eventually, i'll be Zig all the way down, but the language needs to get to the point where it can actually support writing a compiler for itself (and Andrew has some big plans for the way the compiler should work from what I understand).
- floatboth 7y agoHopefully stage1 will remain indefinitely for bootstrapping, like LDC's ltsmaster.
- nicoburns 7y agoCompilers have to be bootstrapped from another language (most commonly C and C++) to get going. Zig is only just getting to a point of maturity where it would be feasible to self-host, and it's still missing any sort of object/trait system, which are the sorts of things you really miss on large projects.
- deleted 7y ago[deleted]
- runevault 7y agoIt isn't even 1.0 yet, far too early to be talking about bootstrapping the compiler.
- olodus 7y agoI love Zig and have played around a bit with it this summer. I do really wish the standard library was better documented though. Think I saw that would be coming soon though so i hope I'll have a even better time with it when I come back to it next time. I would call myself an intermediate programmer with ok knowledge of C and it was for me sometimes hard to understand how I would do some stuff in Zig. Most things are very much the same but with some small changes that I understand why they are there but trip over the differences when trying to do certain things. Besides stdlib documentation I would also want some better examples, but that is probably something that cones with larger adoption. I find Zig together with Rust as a really strong combo of languages that makes one hopeful for the future of system programing.