this post was submitted on 03 Oct 2024
38 points (86.5% liked)

Programming

17398 readers
102 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 !webdev@programming.dev



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.

@programming@programming.dev

you are viewing a single comment's thread
view the rest of the comments
[–] yoevli@lemmy.world 8 points 1 month ago (2 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.

[–] dudinax@programming.dev 3 points 1 month 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.

[–] Ephera@lemmy.ml 5 points 1 month 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.
[–] dudinax@programming.dev 3 points 1 month ago

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

[–] arendjr@programming.dev 2 points 1 month 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.

[–] sukhmel@programming.dev 2 points 1 month ago

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

That might change over time.