5 ms·
> Third: There are a lot of cases where the cost of memory safety just isn't that high, and Zig's mitigations are more than sufficient. But then why not just u
by pcwalton 4y ago
> Third: There are a lot of cases where the cost of memory safety just isn't that high, and Zig's mitigations are more than sufficient.
But then why not just use a GC'd language? It isn't 1995 anymore; most apps are written in GC'd languages. C++ makes sense when you already have a lot of C++ code, but if you're talking about new code, I don't see a lot of room for a language without memory safety.
- verdagon 4y agoThat was a typo, supposed to say "memory unsafety". Thanks for catching that, edited now.
- cztomsik 4y agofor native addons for GC'd languages you probably don't want to introduce another GC, rust is not well-suited for interfacing with FFI, C++ is a bit heavyweight but okish I guess and C is totally unsafe, Zig is just right.
- pcwalton 4y ago> rust is not well-suited for interfacing with FFI That's a surprising comment, given the massive deployments of hybrid Rust/C++ apps at huge scale that exist! Does Zig have any equivalent to cxx for interfacing with C++ code?
- cztomsik 4y agoyou are right about cxx, I made this comment with C FFI in mind. and for that, Zig couldn't have better integration. AFAIK there is no simple way to interface with C++ from Zig, you either have C headers or you write a bit of C++ to export what you need and then you're back in the game. Or you flip it on its head and use zig as C++ compiler and call your zig-parts from C++ but I have no experience with this, I think bun does this.
- mwcampbell 4y ago> rust is not well-suited for interfacing with FFI How so? Packages like neon [1] and rustler [2] suggest otherwise. I'm using both of those in a real product (I'm using neon directly, to write native modules for an Electron app; on the back-end, I depend on an Elixir package that uses rustler). [1]: https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon [2]: https://github.com/rusterlium/rustler https://github.com/rusterlium/rustler
- cztomsik 4y agoI admit it's a long time since I've been using neon so things might have changed but at the time I had a feeling that the whole thing is very fragile and not really safer than if I was using pointers directly. Especially, if you callback into JS and that calls back to native then I think you don't have any guarantees from rust anymore (aka you are being lied) because compiler cannot not know about that. Also builds were a bit tricky, it needed node.js headers in proper place, etc. In zig you just include napi.h because zig can import C including macros and everything. Or if you need to call glfw/nanovg/stb/xxx you just @cImport() and it works. Zig also supports C-style strings in a better way and I can't recall all of the obstacles right now but I'm way way more productive with Zig after 1 month than I was with rust after 5ys.
- mwcampbell 4y ago> But then why not just use a GC'd language? It isn't 1995 anymore; most apps are written in GC'd languages. I mostly agree with you, and I'm enthusiastically using Rust. But I'd love to be able to develop new software, with modern developer conveniences, that could run on a 1995 computer. Assuming that implies a 32-bit OS, that seems plausible with Rust, albeit not with std (but alloc should be fine). Maybe I'll play with that for a side project sometime.
- zozbot234 4y agoRust has already been made to compile stuff for 1995 systems, if only as an experiment: https://seri.tools/blog/announcing-rust9x/ https://seri.tools/blog/announcing-rust9x/ / https://news.ycombinator.com/item?id=31112273 https://news.ycombinator.com/item?id=31112273
- pjmlp 4y agoThat includes GC languages like C#. https://medium.com/@MStrehovsky/building-a-self-contained-game-in-c-under-8-kilobytes-74c3cf60ea04 https://medium.com/@MStrehovsky/building-a-self-contained-ga...