5 ms·
I've been trying to understand what Zig place is in the world so I can learn more about it. I like the idea of simplicity in programming languages but, other th
by jvillasante 2y ago
I've been trying to understand what Zig place is in the world so I can learn more about it. I like the idea of simplicity in programming languages but, other than that and since there's Go already, what is the proposition here?
In particular:
- LLVM is not enough, let's write our own compiler.
- Interfaces are an overhead, use comptime instead or roll your own vtables.
- In a world where "memory unsafe" languages are under attack... yeah, we don't care about that.
I'm not trolling, this are serious questions from afar that I would love to figure out before investing time with Zig.
- the__alchemist 2y agoSimple answer: Anywhere you'd use C, and want a nicer language. So: embedded, operating systems, drivers, compilers, PC applications etc. I would love to try it out with a serious project, but am waiting on libs like HALs for microcontrollers, GPU API bindings, GUIs etc to mature to a usable point.
- flohofwoe 2y agoThe Zig stdlib and comptime features like generics and type inspection go way beyond C (and in parts also beyond C++ and Rust) though (e.g. Zig is much more than "just" a C replacement).
- jvillasante 2y agoWell, I use C++ for that today and don't see much benefit in switching really. Switching to a memory-safe language is something that I can support and even sell to my team, but switching to just a "simpler" language I'm not sure...
- rererereferred 2y ago>LLVM is not enough, let's write our own compiler. That is for speed during debug builds. For production builds zig will still rely on LLVM
- zellyn 2y agoOne notable thing about Zig (and Andrew) is their willingness to rethink everything, and a lack of fear of digging all the way down and building their own versions of underpinning things. They believe incremental compilation should be an option, so they have to write their own compiler, linker, etc. They're already pushing the boundaries of what new languages can do, and—eventually—will be expected to do. [Edit: expanding] For instance, completely platform-independent cross compilation is something Go popularized, but Zig really nailed. (In fact, if you use cgo, the generally accepted method for Go cross-compilation is to use Zig as the C compiler!) Another interesting thing about Zig is that it happily compiles C code, but brings more modern package management. Loris Cro has described how it would be quite reasonable (and pleasant) to maintain C code using Zig: https://kristoff.it/blog/maintain-it-with-zig/ https://kristoff.it/blog/maintain-it-with-zig/
- ksec 2y ago>They believe incremental compilation should be an option May be more accurate should be they believe compiling should be insanely fast. And incremental compilation is part of the tools to achieve that.
- jvillasante 2y agoWhat does incremental compilation have to do with writing your own compiler from scratch? Isn't Rust supports incremental compilation as does every language out there?
- pbaam 2y agoI guess he means that in order to achieve incremental compilation they need to write their own code generation and linker for every architecture and format. This is needed because incremental compilation here doesn't just mean storing object files in a cache directory (which has always worked that way). They also want to cache every analyzed function and declaration. So they have to serialize compiler state to a file. But after analysis is done, LLVM will start code generation from the beginning (which is the time expensive thing, even in debug builds)
- flohofwoe 2y ago> - In a world where "memory unsafe" languages are under attack... yeah, we don't care about that. FWIW Zig does offer spatial memory safety, but does not provide temporal memory safety in the language (e.g. "dangling references"). It also fixes most of the 'sloppyness', UB and general footguns in C and C++ (and most memory corruption issues are a side effect of those). Temporal memory safety can for instance be achieved via generation-counted handles (e.g. see: https://floooh.github.io/2018/06/17/handles-vs-pointers.html https://floooh.github.io/2018/06/17/handles-vs-pointers.html and https://github.com/zig-gamedev/zpool/ https://github.com/zig-gamedev/zpool/)
- pjmlp 2y agoA fix that was already available in languages like Modula-2 and Object Pascal, but apparently needs to be packaged in curly brackets.
- mamcx 2y agoI think Rust is the best option for the `Need to make a project` kind of work. It is overall better, IMHO, and the ecosystem and safety pay dividends. But Zig has several nice things (I don't use it directly but appreciate them, and is my way to cross-compile to musl): * Is truly faster to compile * Is far better to cross-compile * Is far smaller * comptime is a much better `macro` language. I don't like the ergonomics of the split on Rust between the 2 styles of macros, where proc-macros is a cliff of complications I think Zig fits the bill for `C is a compiler target`. Whatever I need to integrate with C or generate C I think it is now better to target Zig.
- jvillasante 2y agoI kind of agree but my main language is actually C++ (I know, don't hate me) and, wherever C is a target I just use C++ :)
- deleted 2y ago[deleted]