7 ms·
Zig vs. Rust at work: the choice we made
- l5870uoo9y 2y agoZig language mentioned in the post: https://ziglang.org/ https://ziglang.org/
- emmanueloga_ 2y agoRust language mentioned in the post: https://www.rust-lang.org/ https://www.rust-lang.org/ lol
- l5870uoo9y 2y agoHad to Google it since the post didn't link to either, but I already knew Rust and assumed many of the readers already do. Also haven't had my morning coffee and thus slight irritated :). Relevant linking should be basic part of any post.
- wyldfire 2y agoOh boy, here comes the ZESF ... ;)
- rizky05 2y agoTS language mentioned in the post: https://www.typescriptlang.org/ https://www.typescriptlang.org/
- evmar 2y ago> Zig works with debuggers our developers know out of the box. Is this not true of Rust? I use lldb via terminal and VSCode with Rust, I am not sure what I'm missing.
- greenavocado 2y agoThe author redacts so many interesting details about his employer which apparently serves hundreds of millions of requests per day. How peculiar.
- emmanueloga_ 2y agoI was wondering about that... it is ok to not mention where you work, but here the author highlights the secrecy every two sentences ... I don't understand if it is supposed to be comedic, parodic, or just quirky? Also, it is interesting that anybody would pick any language because of its C interoperability, since pretty much EVERY production ready programming language can interact with C, although I understand Zig is especially good at this.
- greenavocado 2y agoSelf-described "God’s chosen principal engineer." from their x.com
- sshine 2y agoPlot twist: The company really is called [redacted].
- vander_elst 2y ago> Memory safety and "no undefined behaviors" (obviously untrue, but that was the belief and part of the conversation we had to have Trying to better understand this claim, is it because also unsafe rust exists?
- eru 2y agoThere are a few corners of undefined behaviors in Rust outside of 'unsafe' blocks, too.
- estebank 2y agoAre you taking about the open unsoundness bugs?
- eru 2y agoI remember something about being able to transform any lifetime into a static lifetime entirely within safe Rust. But I can't find the link to it right now.
- estebank 2y agoIt's either https://github.com/rust-lang/rust/issues/112905 https://github.com/rust-lang/rust/issues/112905, https://github.com/rust-lang/rust/issues/84366 https://github.com/rust-lang/rust/issues/84366 or (most likely) https://github.com/rust-lang/rust/issues/25860 https://github.com/rust-lang/rust/issues/25860. It can be argued that those are bugs of the compiler, not the language (but in practice that doesn't matter, it's unsound in the only way that matters now!) and that it's very unlikely to be hit by accident (but someone can leverage it intentionally to cause unsoundness in their library, without the presence of unsafe).
- eru 2y agoThanks! Yes, I think it was the last one, https://github.com/rust-lang/rust/issues/25860 https://github.com/rust-lang/rust/issues/25860. But I'm not 100% sure.
- zer00eyz 2y agoI have written some rust I like it. I prefer GO for day to day but I wont turn my nose up at Rust... Cargo on the other hand... I saw someone say "Rust is turning into the language that tokio ate" ... and this is a cargo shortcoming. Zig dependency management feels more Go like, and in my book thats a good thing. I like decentralized. Zig is going to be what I build my next "fun" project in. Im actually excited to spend that time when I find it. I haven't felt that way about something new in a long time.
- sedatk 2y agoZig is basically a more ergonomic C while Rust is an entirely different memory-safe language. I don't see why Rust would ever get picked over any other language if high-performance memory safety isn't a priority. And, if it IS a priority, I don't see why anyone would pick any language other than Rust.
- jakobnissen 2y agoI program in Rust and dabbled in Zig. Rust has many more advantages than memory safety, including: * Great error messages (at least since I don't do async stuff) and a helpful linter and compiler * Relatively high-level APIs, especially compared to Zig. I can do much more in fewer lines of code in Rust * Larger ecosystem, including more available packages and tutorials/learning materials * More stability, since Zig is not at 1.0
- sedatk 2y agoAbout Rust's friendly error messages: that's pretty much a self-fulfilled prophecy because compiler errors in Rust are way more prevalent due to stricter constraints imposed by the language. Therefore, Rust must show much better error messages to compensate for its ergonomical disadvantages. So, I don't see that as an absolute win. All the remaining arguments are about maturity. Nothing prevents Zig from attaining them in the future. As a final note: I love writing code in Rust and never used Zig, but I can relate to the demand of ergonomics from a programming language and Rust is quite handicapped on that front, IMHO.
- estebank 2y agoThere are more error cases for invalid Rust code than for other languages, that might be true, but the friendliness of the errors is a consequence of project phylosophy and engineering effort, not a foregone concussion. Some errors fill in on ergonomic holes, but on the whole they are an attempt to make the DX as good as it can be and making the compiler part of the learning experience, not an inscrutable tool that you need a mentor and experience to even have a chance of understanding.
- 2y ago
- dureuill 2y agoThis feels very shortsighted to me. "Easy to learn" and "easy to hire for" are an advantage in the first few weeks. Besides, we now have data indicating that ramp up time in Rust is not longer than in other languages. On the other hand, serving millions of users with a language that isn't even v1 doesn't seem very reasonable. The advantages of a language that is memory safe in practice and also heavily favors correctness in general boosts productivity tenfold in the long term. I'm speaking from experience, I switched from C++ to Rust professionally and I'm still not over how more productive and "lovable" the language in general is. A language like zig isn't bringing much to the table in comparison (in particular with the user-hurting decisions around "all warnings are errors, period")
- incrudible 2y ago> The advantages of a language that is memory safe in practice and also heavily favors correctness in general boosts productivity tenfold in the long term. Does it though? There are many languages that fit this description, you would choose Rust if for some reason you also need good performance. However, if you heavily interop with C/C++ safety goes out the window anyway, and it probably never mattered much in the first place.
- dureuill 2y ago> There are many languages that fit this description I find that in practice not, especially if you further limit that to imperative languages. Note that I mentioned memory safe AND heavily favors correctness. In that regard, Rust is uniquely placed due to its shared XOR mutable paradigm. One has to look at functional languages that completely disable mutation to find comparable tools for correctness. Allegedly, they're more niche. > However, if you heavily interop with C/C++ safety goes out the window anyway I find this to be incorrect. The way you would do this is by (re)writing modules of the application in Rust. Firefox did that for its parallel CSS rendering engine. I did it for the software at my previous job. The software at my current job relies on a C database, we didn't have a memory safety issue in years (never had one since I joined, actually). We have abstracted talking to the DB with a mostly safe wrapper (there are some unsafe functions, but most of them are safe), the very big majority of our code is safe Rust. > it probably never mattered much in the first place It does matter. First, for security reasons. Second, because debugging memory issues is not fun and a waste of time when alternatives that fix this class of errors exist.
- samwillis 2y agoI think it's interesting to observe the development speed of Bun vs Deno when comparing Zig and Rust. Bun is written in Zig and links to the WebKit's JavaScriptCore. Deno is written in Rust and links to V8. It seems to me that the development of Bun is significantly faster than Deno, how much of that is down to the easy of interoperability of Zig and C/C++ vs some of the hoops you have to jump though when using Rust with a C/C++ lib? (I may be wrong on this an the Bun team are just exceptionally quick)
- jedisct1 2y agoThe Bun team is really good, and Zig is a productive language. But there's also the simple fact that when you reimplement something, it's always going to be easier and faster than it was to write the previous implementation. You know from day one what the baseline of the project will be, and can skip all the refactoring steps the predecessors had to do in order to implement new features. You also know what worked for them and what didn't. And what users liked and what users didn't use and ended up being code rot, so you can prioritize accordingly.
- uh_uh 2y agoI thought the creator of Deno, Ryan Dahl, is also the creator of NodeJS. So by your reasoning, the development of Deno should go faster than Bun's, no?
- deleted 2y ago[deleted]
- rapsey 2y agoThese kinds of posts can pretty much always be summerized down to that is what we wanted to use. The arguments are very weak and unconvincing. People love to say, use the right tool for the job but no one actually does it. Developers will use what they know or what they feel comfortable using.
- devnull3 2y agoC-interop while certainly more involved in Rust compared to Zig, it is generally a one-off effort (for most projects). wards it's generally an incremental effort to map additional C code. I am not sure I would make this an important factor but to each his own.
- jedisct1 2y ago> "WASM support was just as smooth in Rust as in Zig". There are still way too many Rust dependencies that don't support WebAssembly, and even functions in the standard library that compile but will crash at runtime on WebAssembly. And if a dependency requires C code, `cargo-zigbuild` is required to compile it anyways. My experience with Zig is that pretty much everything compiles out of the box to all the supported targets, and works the same way. This includes code using SIMD. I also like the fact that the code can be optimized for the runtime's feature: adding -mcpu=baseline+simd128 compiles everything for wasm runtimes with support for SIMD, including the C library ("wasi-libc"). This is not specific to the wasm target, but the fact that even the libc is recompiled with the same optimization flags as the rest of the code is neat. You can really optimize the code for speed, size or a specific target. WebAssembly modules compiled from Zig code are also very small and memory efficient, without being forced to use a "[no_std]" mode. That can make a big difference if you have to distribute them, or are billed according the resource usage. > The Zig build system is amazing and 100x better than our makefiles. This. People often think Zig is just a language. But it's a toolchain, that can be used even for code not written in Zig. It's a fantastic replacement for makefiles / CMake / ccache / hacky shell scripts, with seamless cross-compilation and webassembly support.
- OutOfHere 2y agoHow did you learn Zig if it has no book?
- mstef 2y agobesides the docs, there is also all the source code in /usr/lib/zig/std... very useful to learn zigisms and the API of the std library itself...
- dualogy 2y agoNot sure about OP, but here's how I did it back when I dabbled in it: had prior programming experience, read the docs. =)
- dragonelite 2y agoRead the docs, do ziglings for a couple of nights to make it stick a bit better. Then just start making small things like the "ray tracing in a week" or "Writing an interpreter in Go" book but only the parser part. I usually don't even finish those starter projects its just to get a better feel how to do structs, modules etc.
- jpc0 2y agoA question for those who are in the Zig camp. I've heard talks that zig is now mostly stable and there are no big api changes expected but I haven't been able to find any official statement on that, is this true?
- kristoff_it 2y agoThe language is stable enough that we're stopping recommending people to use unstable builds and instead use the latest tagged version. That said every new release has a section about breaking changes and it's never empty. I would say that calling Zig stable is a huge overstatement, but it is true that the language has been fairly stable in the last few releases. The standard library on the other hand does keep seeing a lot of changes and more in general is still due a big set of breaking changes when it will be officially vetted (it currently grows organically based on needs of the compiler itself or very common use cases). Lastly, the current stability is in great part caused by the current focus of the core team on custom backends and incremental compilation. Once that's done, I would not be surprised for more language-level breaking changes to pick up again.