Edit: Thank you all for your responses!
Edit: Thank you all for your responses!
For some people the huge 'surface area' and strict type system of Rust is a big turn-off, while others want exactly that from a programming language.
One main difference is that Rust is guaranteed memory safe with generally no runtime overhead for that safety. It also has protections and abstractions to make multithreaded code safe and generally correct.
Depends on your definition of safety and correctness. Async Rust does not prevent deadlocks and make them very difficult to detect
Systems programming can be done in ocaml or any language really where there is some documentation on the runtime how not to trigger the GC or flags that can be passed to custom set GC policy
Hacker News discussion: https://news.ycombinator.com/item?id=46153466
For hobby projects, zig will get you *much* closer to the underlying system. So if your goal is systems programming where you're responsible for and get to play with the system itself. Zig will get you there much faster, and the language wont take much time to learn and have fun with.
Surely someone will now attempt to correct me, by asserting it's impossible for anyone to write safe code without rust, and it's improper for me to even suggest Zig. But I'm enjoying the language a lot. It's easy to pick up and understand, and importantly it gets out of your way quickly so you can build exactly the system you want.
For more complex or professional projects however, I would still recommend Zig but more because I can't stand rust. It bothers me that it rejects valid programs because the compiler is unable to prove what I can. So the additional dance rust requires ruins an otherwise fine language.
edit: my default language before zig was also python, so feels reasonable to also mention that I'm pretty sure it'll be significantly easier to transition from python into Zig rather than into rust. There's a number of idioms and expectations from python that fit well in zig, but dont fit in rust.
If you don't have time to learn both, then learn Zig, as it requires much smaller time investment (though do try to find time for both).
I see Zig as being a lot more in C tradition and lineage with nicer and safer memory management techniques. Also comptime (Lisp-ish there?)
My two cents
It links out to the standard library documentation, which is also comprehensive and easy to navigate: https://ziglang.org/documentation/master/std
no, the docs really don’t cut it.
it is strongly opinionated about the correct way to do things but it leaves you to your own devices to piece together an understanding from source code, ziggit, and discord.
That is currently in the process of changing. Of course people are discussing things that are changing.
> no, the docs really don’t cut it.
Yes they do :) - source: have written multiple small projects in Zig.
I encourage you to actually read the page I linked from top to bottom if you are interested in learning Zig. I did it because mitchellh mentioned in an interview that it's what he did. It's easy to follow, useful, and not an overwhelming amount of information.
the source code has always been the main source of truth and documentation. which means no documentation. std is littered with undocumented behaviours, the build system is still something many people use half-blind. and while i’m fine with breaking changes, but the way they’re just dropped onto our laps with, it seems, almost zero thought put into how to acquaint the users with it. (i started to feel almost as if patience in introducing the concepts and interfaces is one of those things that is below andrew)
while i admit that zig’s authors’ claim to technical excellence is deserved, communication has never been excellent. i’m sure there are people who would gladly involve themselves in documentation efforts, but the chances of receiving andrew’s ire and demeaning disposition are so great that it might be paralysing such efforts leaving it to the Guy himself who's not too wont to educate others.
Zig is gaining integration into larger projects (Ghostty, TigerBeetle, Roc, Ubers build system come to mind), but it's not yet achieved Rust's success
Rust feels like "let's take the best safety features from both", while Zig feels like "let's take the best transparency from both". In a way, Rust's traits are more foreign to C++ than Zig's comptime, as Zig has similar duck typing (though the ergonomics are much cleaner, especially with @compileError).
Note that there are a number of domains where Zig might be a practical option in the future, but aren't now due to library support. With Rust, you will reinvent wheels more than most people have an appetite for. In Zig, you will do this for most things.
The main complaint about the borrow checker is that what seem like trivial changes can have subtle implications that require wildly different ownership patterns to be made correct. Rust tells you something's wrong. If you don't thoroughly understand how you're using pointers (which few people do), it can feel like trivial changes exploding into much larger refactors than you'd need in languages where the rules aren't statically enforced.
- Do you like filling out the type annotations in Python (making sure linter check passes)? Do you like TYPES in general?
- Do you like working with memory (crushing memory bugs, solving leaks)?
- Do you prefer imperative or functional approach more?
I do like working with memory, seeing a custom slab allocator used in production code was one of the more interesting aspects of the little experience I had with c++, but always having to be "on guard" so as to not shoot myself in the foot with pointer manipulation was kind of exhausting.
I like both.
It really depends what you mean by "interesting" :-)
Disappointingly as a Rust dev, I don't actually see a lot of Rust being used for "systems" development (OS, driver, DB internals, embedded, etc), but increasingly for network services/web services/web stack work, heavily biased towards tokio async driven applications. It's a lot of engineers living further up the stack, leaning on frameworks, and in applications with very large dependency tree footprints. As a % anyways. There's a lot more Rust code out there than Zig.
I think Zig has a far more minimalistic thing going on and I like that. I find its type system a lot more primitive, and would miss ADTs/enums, and the borrow checker etc. but I like its overall philosophy better.