6 ms·
I'm shipping in Rust but any reason to do so in Zig ? What does it offer over Rust ? Something tangible benefit to end user or developer using ai assisted devel
by zuzululu 2mo ago
I'm shipping in Rust but any reason to do so in Zig ? What does it offer over Rust ? Something tangible benefit to end user or developer using ai assisted development ?
- rahen 2mo agoUse Rust if you're not writing code yourself. The borrow checker will catch all kinds of bugs that AI-generated code will happily compile in Zig but will blow up as UB at runtime. Zig's value prop is different and closer to a modern C: it fits in your head and maps fairly closely to assembly. There is no hidden control flow or hidden allocations, so you can tweak performance at a very low level. You're the pilot, not the compiler. Rust trades the low-level clarity for compiler-enforced safety. If you're not a code artisan or don't care about being one, then please use Rust.
- eptcyka 2mo ago> You're the pilot, not the compiler. This to me reads like an LLMism.
- solatic 2mo ago> The borrow checker will catch all kinds of bugs that AI-generated code will happily compile in Zig but will blow up as UB at runtime. This has not been my experience; Claude does a great job of writing unit tests for the Zig code, and combined with Zig's fuzzing features and a Python-based integration testing suite, I have avoided hitting runtime UB so far. In exchange, I get much faster compile times, which are important for the agentic development loop.
- zuzululu 2mo agoCan LLMs not write Zig code ? I'm not really understanding your explanation for why we can write other languages with LLM but not Zig here. > Rust trades the low-level clarity for compiler-enforced safety. If you're not a code artisan or don't care about being one, then please use Rust. Not really seeing the connection here. What do you mean by code artisan? Are you trying to gatekeep Zig because you think Zig is too difficult for LLMs?
- rahen 2mo agoYou asked if there was "tangible benefit to end user or developer using ai assisted development". My answer is no, it can be done but has no benefits for this use case. Use Rust here, because its compiler acts as an AI safety net. Being a code artisan is not gatekeeping. It means if you're used to being close to the metal and sometimes know better than the compiler, Zig is for you. If you're not, use Rust.
- 9dev 2mo ago> if you […] often know better than the compiler With all due respect, that tickles my spidey senses. People claiming to know better than a compiler about low-level details of their code are most often either engaging in premature hyper-optimisation, or suffer a specific kind of greybeard hubris IMHO
- applfanboysbgon 2mo agoThe idea that humans can't solve a specific problem more efficiently than a generalised algorithm that has to work for all code ever written in the language is a lie that JS script kiddies tell themselves to justify remaining ignorant without feeling bad about it.
- 9dev 2mo agoOh, humans can definitely do that, in some capacity, if they're attentive, slept enough, aren't hungry, or in emotional distress, for a limited amount of time. A generalised algorithm can do this consistently, billions of times, which happens to be the amount of problems involved in building an application.
- applfanboysbgon 2mo agoWhich is why we don't write entire programs in raw assembly, but that doesn't mean it's actually difficult to do better than a compiler. You focus your efforts on where benchmarking and profiling tell you your bottlenecks are in your hot paths. If you actually engage in this in a regular basis, you will recognise that despite the myth-building and fear around writing low-level code, compilers do "stupid" inefficient stuff all the time, and it's not hard to do better than them with the specific context of your project in mind.
- je42 2mo agoSo far claude has been fine to generated zig code. Dont have lots of issues. Tijy local models have more problems with zig, need additional instructions. In general, what helps is to instruct ai to use test coverage to ensure the cover all edge cases with tests.
- Ygg2 2mo agoUse Rust if you want to write in a memory safe, high performance language. > Zig's value prop is different and closer to a modern C: it fits in your head and it maps fairly closely to assembly. This can't be correct for the simple reason that it has both a modern optimizing compiler (LLVM) and UB. A modern compiler will try to autovectorize your code, so you don't really know what the assembly will be. UB gives compiler license to rewrite your code however it sees fit.
- lowbloodsugar 2mo ago> A modern compiler will try to autovectorize your code, so you don't really know what the assembly will be. Looking at what the compiler actually did is an ancient tradition. I’ve even done it with Java. Seeing five virtual calls with bounds checking all over get turned into a single load instruction has to be seen to be believed.
- bsaul 2mo agoit's also my opinion. Which makes me wonder : isn't there an opportunity to create a variant of rust that would make absolutely zero compromise on UB and safety at the detriment of user experience ( which we don't care about now, with AI generating the code) ? Like programming in a kind of super strict IL. Or the opposite : super poweful, super abstract language, yet extremely strict.
- flohofwoe 2mo agoLLMs are actually pretty good at finding potential memory corruption issues in unsafe langauges upfront, to a point where I wonder if it even still makes sense using Rust with its slow compile-edit-test loop in a fully automated code generation scenario.
- ModernMech 2mo agoPart of the reason the compile-edit-test loop is slower than in other languages is because Rust is doing a whole borrow checking phase other languages don't. I don't see why it'd be faster or more accurate to get an LLM to do the same static analysis as the Rust compiler. Although I'd be interested in an analysis of how much each would cost in dollars.
- bombela 2mo agoIt's the compilation that is slow, not the checking. You can observe this by comparing "cargo check" and "cargo build".
- ModernMech 2mo agocargo clean cargo check Finished `dev` profile [unoptimized + debuginfo] target(s) in 2m 40s cargo build Finished `dev` profile [unoptimized + debuginfo] target(s) in 3m 12s cargo clean cargo build Finished `dev` profile [unoptimized + debuginfo] target(s) in 3m 15s shrug
- bombela 2mo agoAnd the difference is more useful in the more common scenario of editing code and checking it. Though those days, language servers like rust-analyzer do essentially replace cargo check. Taking the alacritty project and modifying the source files to pretend something happened: > cargo clean Removed 1602 files, 545.8MiB total > cargo check [...] Finished `dev` profile [unoptimized + debuginfo] target(s) in 17.12s > cargo build [...] Finished `dev` profile [unoptimized + debuginfo] target(s) in 23.04s > find alacritty_terminal/ -name "*.rs" | xargs-I{} sh -c 'echo >> "{}"' > cargo check [...] Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.00s > cargo build [...] Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.37s I wish it was faster, but I will take the speedup that I can!
- lowbloodsugar 2mo agoI’ve shipped games written entirely in assembly. I now work on a large service you have heard of. I graduated manga cum laude. I’m not smart enough to write systems in C or Zig that don’t have bugs. The question I ask myself is “would I write a game in Rust?” Zig seems like a better fit: you can be clever without being chided by the borrow checker. But as a “code artisan”, there’s an interesting challenge in making it work with Rust. I might use Zig on a project if it was just me. I wouldn’t use it with the a team that I didn’t hand pick. Smart people like Zig. Smart people like Rust. Smart people like LLMs. It’s a big Venn diagram. It be great if we could not bash each other.
- applfanboysbgon 2mo agoI often use LLMs to build and modify open-source tools for personal use and Rust's compile times are disgusting, eg. Codex CLI taking over 15 minutes to recompile on my fairly high-end machine. Zig's incremental compilation optimizations are amazing, giving near-instant recompiles measured in ms instead of minutes. I would certainly classify four orders of magnitude faster compilation as a tangible benefit even if you're not writing the code by hand.
- zuzululu 2mo agoRust is quite slow but that is an interesting benefit but still not sure what the trade offs are, Rust has a huge mature ecosystem and there are lot of jobs for it. Are you able to ship faster with Zig vs Rust? How did you arrive at the 4x figure? I'm really puzzled why people are so angry over using ai assistance with Zig. LLMs are always going to be able to write better code faster and better than anyone who calls themselves code artisans in this day and age. I think this comment posted a while back someone who worked on Zig is pretty telling: > The key problem with Zig nowadays is how much of its community and adoption is driven by anti-Rust sentiment. As a result, while Rust puts beginner onboarding and documentation at the center of its culture, as opposed to the “C neckbeard”'s culture, Zig is going the other way around. And ultimately this didn't stop people from using AI generating Zig code as much of the users in the thread are already using it to ship quality faster. Happy to use the work the community outputs and culture is largely irrelevant when prompting LLMs outputs code that doesn't really require any intimate knowledge with the syntaxes
- bigstrat2003 2mo ago> LLMs are always going to be able to write better code faster and better than anyone who calls themselves code artisans in this day and age. LLMs can't write better code faster than any reasonably competent human. They suck at writing code, and if you're outsourcing programming to them the software you produce will suck as well.
- hiccuphippo 2mo agoHow about the overall time LLM+compilation? What does it matter the compile takes 15 minutes if the LLM writes the code faster? Do we even care about compilation time if we set it to work on a task and return some time later to see the result?
- hiccuphippo 2mo agoZig lets you be very explicit about what you want. Zig's hello world takes 3 or 4 lines where other languages take 1. That is how much other languages make decisions for you. Some people care to make those decisions themselves.
- applfanboysbgon 2mo agoThis is the weirdest basis for comparing a language I've ever seen. Zig is one line as well, `std.debug.print("Hello, world!\n", .{});`, unless you're counting defining main and its brackets as 4 lines, in which case... Rust has that too, Java is 7 lines and C# is 8 lines to import System library and define the Program class as well if you're not using top-level statements / implicit usings. --- Edit for replies complaining I used debug.print: Okay, `try std.io.getStdOut().writer().print("Hello, world!\n", .{});`. Still one line, more explicit with chained methods, but that still just goes to show you how arbitrary this metric is -- Zig's standard library makes you be more explicit with one function, but it doesn't make you be as explicit with another one that works essentially the same way but writes to a different stream, ergo this has nothing to do with the language's inherent explicitness but rather comparing the implementation of a single random function.
- solatic 2mo agostd.debug.print is, as its name suggests, for debug output, not for program output. In Zig, you create a buffered writer for the stdout file handle, write hello world to the buffer, and then flush it. It exposes what's actually happening underneath.
- denismenace 2mo agoAs the name suggest `std.debug.print` is a short hand for debug printing. In a CLI app for example you should use IO.
- ErenayDev 2mo ago(reply to edit) small typo fix: instead of `std.io`, it should be `init.io`. `init` is first parameter in `main` function.
- ErenayDev 2mo agoZig's compiler somehow feels lightweight to me compared to Rust's. When i develop something in Rust, the compiler and LSP is overheating my CPU. So im using Zig nowodays for long life my laptop. When I had problems in my Zig codebase(latest version), the LLM cant resolve my problem. It kept giving me results based on older versions of the Zig code. This was due to breaking changes in every version. Thats why I no longer ask the LLM for help with Zig-related code. The folks on Zig Discord server and its forum, helps me very much.
- pyrolistical 2mo agoGive it agent instructions in the major breaking api changes. I force around Io stuff. Then point it to the zig source code. Sure it wastes a bit of time always figure it out when it fails to compile. This is why I’m excited to see qwen3.8 27b removed a bunch of knowledge for more reasoning. Baked in old zig api is worthless