this post was submitted on 03 Oct 2024
47 points (89.8% liked)

Programming

17123 readers
111 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Zig vs Rust. Which one is going to be future?

I think about pros and cons and what to choose for the second (modern) language in addition to C.

@[email protected]

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 16 hours ago

Since you're asking today the answer is Rust because it is already more mature. In 5-10 years if you asked them the answer might be different if zig sticks around.

This is no shade against zig! It's just very new. It doesn't have a 1.0 release yet.

Also, they're very different languages with very different goals. They aren't necessarily competing in the same space.

[–] [email protected] 13 points 1 day ago* (last edited 1 day ago)

Zig is a modern C. Rust is a (modern) alternative to C++. So two different languages can exist alongside each other, just like C and C++.

[–] [email protected] 28 points 1 day ago* (last edited 1 day ago) (1 children)

Google has already started to use Rust in their android operating system. Linux started getting Rust stuff. Rust has the speed of C/C++ while having memory safety. Zig does not have the same memory safety as Rust, it's a mere C/C++ alternative. Does that answer your question?

[–] teolan 3 points 1 day ago

Windows now also has Rust in the Kernel

[–] [email protected] 14 points 1 day ago* (last edited 1 day ago) (5 children)

Is zig memory safe by design? If not, rust will "win". Large companies aren't going to hire for an unknown or unpopular memory unsafe language when they already have C or C++ - there's just no contest.

Last I read, zig didn't even have a standard string library. Unless that changes, it won't even be a viable alternative to C/C++.

Edit: I checked and got this

the Zig language, like C, entrusts memory management to humans, placing full trust in human development. Zig then provides some memory safety checks to ensure memory safety. However, it still lacks the strict compile-time guarantees of Rust’s ownership system and borrow checker. Therefore, when writing Zig code, developers need to pay more attention to potential memory safety issues and ensure that errors and exceptional situations are handled correctly.

Rust Magazine

Anti Commercial-AI license

load more comments (5 replies)
[–] [email protected] 23 points 1 day ago (4 children)

Rust. It's a qualitative improvement over the old ways.

The future won't belong to Rust itself, but one of its descendants. Rust is too clunky to be the ultimate expression of its best ideas.

[–] yoevli 11 points 1 day ago (3 children)

In what ways do you feel Rust is too clunky and how do you think it could be improved? Not looking to argue or even disagree necessarily; I'm just curious where that perspective comes from.

[–] [email protected] 7 points 1 day ago

Async is weird, and the generics salad stuff is clunky.

Just my gut feeling as well.

[–] [email protected] 4 points 1 day ago (2 children)

Here's some of my personal complaints. I don't in general know how to fix them.

  1. proc_macros need their own crate

  2. generics cause problems. Many useful macros can't handle them. Try using a generic that's a complex async function, then pass a closure to it.

  3. There's this kind of weird mismatch where sometimes you want an enum wrapping various types, and in others generics. I find my data flows switching back and forth.

  4. async in rust is actually really good, but go does it better. I don't think rust could match go without becoming a different language.

  5. Traits are just a big mess. Trait implementations with generics have to be mutually exclusive, but there aren't any good tools to make them so. The orphaned trait rule is necessary to keep the language sane but is incredibly restricting. Just today I find certain a attribute macros for impls that doesn't work on trait impls. I guess I have to write wrappers for every trait method.

  6. The "new type" pattern. Ugh. Just make something like a type alias that creates a distinct type. This one's probably easy to fix.

  7. Cargo is truly great, but it's a mystery to me right now how I'm going to get it to work with certain packaging systems.

To me, Rust is a bunch of great pieces that don't fit together well.

[–] [email protected] 4 points 1 day ago (2 children)
  1. Cargo is truly great, but it's a mystery to me right now how I'm going to get it to work with certain packaging systems.

Yeah, Cargo itself doesn't deal with any of the bundling after the executable is built.

For that stuff, the efforts are certainly still ongoing. There's no grand unified tool yet.

If you just want e.g. a DEB file, then you probably want this: https://crates.io/crates/cargo-deb

But if you want to do more in CI, then there's kind of three popular options that I'm aware of.

  • just: More or less a shell script runner, and kind of like make.
  • cargo-make: A lot of effort has been put into this, it's certainly got a good amount of features, but personally not a fan, since it makes you write a custom TOML format and then ideally you should be writing a custom script language, DuckScript. You can also use Rust scripts with it, which we tried, but there was just no way of passing parameters between tasks.
  • cargo-xtask: This is not a tool, it's a pattern, basically just build your own build tool. It does have its downfalls, you're not going to build good caching into your own build tool, for example. But in principle I find this quite workable, as you get to write your CI code in Rust. There's also more and more community-made libraries to aid with that.
[–] [email protected] 2 points 1 day ago

Thanks, I've save your comment. I haven't heard of any of these.

[–] [email protected] 1 points 1 day ago

Great suggestions! One nitpick:

But in principle I find this quite workable, as you get to write your CI code in Rust.

Having used xtask in the past, I’d say this is a downside. CI code is tedious enough to debug as it is, and slowing down the cycle by adding Rust compilation into the mix was a horrible experience. To add, CI is a unique environment where Rust’s focus on correctness isn’t very valuable, since it’s an isolated, project-specific environment anyway.

I’d rather use Deno or indeed just for that.

[–] [email protected] 2 points 1 day ago

Rust is a bunch of great pieces that don't fit together well.

That might change over time.

load more comments (1 replies)
load more comments (3 replies)
[–] [email protected] 7 points 1 day ago (1 children)

It's too early to tell.

Rust has a killer feature and a tonne of buzz, but poor ergonomics.

Zig is developing into simple elegance and wonderful interop, but has more work to do before it will be widely usable.

It's entirely possible that ideas and lessons taken from them will inspire another language that ends up eclipsing them both.

[–] [email protected] 14 points 1 day ago* (last edited 1 day ago) (3 children)

I would say at this point in time it’s clearly decided that Rust will be part of the future. Maybe there’s a meaningful place for Zig too, but that’s the only part that’s too early to tell.

If you think Zig still has a chance at overtaking Rust though, that’s very much wishful thinking. Zig isn’t memory safe, so any areas where security is paramount are out of reach for it. The industry isn’t going back in that direction.

I actually think Zig might still have a chance in game development, and maybe in specialized areas where Rust’s borrow checker cannot really help anyway, such as JIT compilers.

load more comments (3 replies)
[–] [email protected] 14 points 1 day ago (3 children)

Unless Zig starts its own cult, I feel Rust will win in the end.

[–] [email protected] 9 points 1 day ago

The thing with rust is that it is awesome. It does exactly what it promises and everyone keeps going on about.

If you want to talk cult talk to c developers. They are so indoctrinated. They say things like "undefined behaviour is fine you just have to code around it" "it's great there's almost no surface area to the standard lib as you can now trust your fellow developers to perfectly write all constructs" "yeah it causes uncountable security vulnerabilities (even when written by it's foremost experts) but that's unskilled developers and not a language problem"

load more comments (1 replies)
[–] [email protected] 4 points 1 day ago

Why not both?

[–] 9point6 9 points 1 day ago (3 children)

Which one's in the Linux kernel?

load more comments (3 replies)
[–] [email protected] 9 points 1 day ago (9 children)

Who wants oxidised Metal when you can take off every Zig! You know what you doing!? Move Zig. For great justice.

load more comments (9 replies)
[–] [email protected] 8 points 1 day ago (12 children)

Isn't exactly this kind of thing what is mostly responsible for the demise of Perl?

As I heard it told, the developers of Perl worked so long & hard on the next version after Perl 5, but then veered off to make a new language (Raku) and despite the reality being otherwise, people feared so much that Perl would die (i.e. that 6 would never materialize) that in the meantime "everyone" had switched to Python (despite it clearly being an inferior language - hehehehe:-P).

So that would be a "con" I suppose, if fights over which language is better ends up diluting efforts to work on or with either.

load more comments (12 replies)
[–] ZILtoid1991 1 points 1 day ago (1 children)
[–] [email protected] 4 points 23 hours ago

Duzt.

There, i coined it.

[–] Solemarc 5 points 1 day ago

I assume they will both be here for the long term but for different things.

I don't think there's much crossover between the two though and I'm not sure this'll change. Rust code looks a lot like modern strongly typed languages and the memory/performance stuff is abstracted away for most use cases. While Zig looks a lot like C with pointers and writing your allocators. I think Rust is probably easier to grasp for most Devs.

Rust is also already entrenched, android, chrome, windows, JS ecosystem, Python ecosystem, it's everywhere. While Zig doesn't have the adoption yet.

[–] [email protected] 2 points 1 day ago (1 children)

What are your goals?

If you want to learn another language just for the fun of it (the best reason) than learn both.

Of you want to improve your tool set to be able to land a job, then there is no good answer. Probably some other high level language like Python, Java, JavaScript, C#. Etc.

Also: Zig bay be easier to get started when coming from C, because it is mostly imperative.

Rust introduces concepts from functional programming. This could be interesting for you, of you don't have any experience in functional programming to get in touch with other programming styles. Or not, of you explicitly don't want to learn such things.

I use both languages, and I enjoy both. Shameless plug: I've written a blog post ~ 2 years ago what I like about each language: https://zigurust.gitlab.io/blog/posts/three-things/

load more comments (1 replies)
load more comments
view more: next ›