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

8 points

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.

permalink
report
reply
18 points
*

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++.

permalink
report
reply
23 points
*

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?

permalink
report
reply
33 points

Honestly C is the future. I don’t know why people would move from C to any other language. It does the job well enough that there’s no reason not to use it.

Think about it. Every modern application depends on a piece of code written in C, not Rust or Zig or any other language (except assembly). It can be used to solve any problem, and works in more places than any other language.

These arguments about “security” and “memory safety” are all pointless anyway in the face of modern code scanning tools. Cross-platform dev can be done trivially with preprocessors. If that’s not enough, I don’t know what to say. Get better at writing C obviously.

Lifetimes and UB should all be kept in mind at all times. You can explicitly mark lifetimes in your C code if you want using comments. Any index-out-of-bounds bugs, use-after-free, etc are just signs that your team needs more training and better code scanning utils. Write more tests!

Anything more complex than a simple typedef is just a sign that you’re over-engineering your solution. #include is both simple, and does exactly what you’d expect any reasonable language to do - paste your referenced code inline. It’s genius, and doesn’t require any complicated explanations on namespaces and classes and subclasses and so on.

So which will be the future? C obviously.

/s

permalink
report
reply
26 points

You got me in the first 3 quarters, not gonna lie!

permalink
report
parent
reply
24 points

The number of people that genuinely believe this ( I saw the /s) … Tells me that they haven’t written any useful C or C++ code

permalink
report
parent
reply
11 points

… or worked in a large team with juniors and members coming and going over a long period of time.

permalink
report
parent
reply
5 points
*

Or worked on a similar team where the C & C++ was mostly written over a decade ago by dudes in another country who loved multi threading, and some of the “new” features were half-completed about 5 years ago, and nothing is documented, and oh yeah not a single person who did any of that still works at the company. Team is made of great people but all have been here for 0-3 years.

The idea of Rust being roughly as fast and low level as C++ but with improvements to memory safety and concurrency sounds heavenly. I know it’s in the back of most of our minds to look into it for the next big project.

permalink
report
parent
reply
10 points
*

I’m not going to say that C is unusable by any means (and I’m not saying you are saying that). It’s a perfectly usable language. I do think that more people would benefit from exploring other options though. Programming languages are tools, not sports teams. People should familiarize themselves with many tools so they always have a good tool to use for any job.

I think a lot of people believe this because there is some truth to parts of it. I think we see languages like Rust and Zig (and others) popping up to try and solve specific problems better than others.

As for OP’s post, there is no single “C successor” or anything like that. People will use the best tool they know of for the job whether that’s C, Rust, C++, Zig, Python, C#, etc. Many languages will “replace” C in some projects, and at the same time, C will replace other languages in some projects (likely to a lesser extent though).

(Not /s this time)

permalink
report
parent
reply
8 points

Oh completely. C is here to stay, C has surpassed language and become protocol cause of libc being so centric to Unix like languages. But it needs to be done carefully and thoughtfully. The other languages are solving some of the pain points C has which I think a lot of people would be better off using than C.

permalink
report
parent
reply
26 points

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.

permalink
report
reply
8 points

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.

permalink
report
parent
reply
7 points

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

Just my gut feeling as well.

permalink
report
parent
reply
3 points

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.

permalink
report
parent
reply
4 points
  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.
permalink
report
parent
reply
2 points

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

That might change over time.

permalink
report
parent
reply
1 point

Have… you met C?

permalink
report
parent
reply
1 point

Do tell.

permalink
report
parent
reply
-1 points

That guy that causes pretty much every major code based security vulnerability?

permalink
report
parent
reply
-5 points
*

What does Rust improve over its predecessors? The only really new thing is the borrow checker, which is only useful in very low-level programming.

permalink
report
parent
reply
10 points

It also has real type safety and thread safety.

permalink
report
parent
reply
9 points

What do you mean by its predecessor? C++? I think rust has a bunch of advantages. For one, designing a new language today gives you the benefit of hindsight meaning that they have a more cohesive set of features and a nicer standard library compared to C++ that has some bloat and cruft as a natural result of it evolving over several decades. It’s also much easier to reason about undefined behavior in rust thanks to unsafe. Algebraic data types are really nice and traits are better than classes.

The borrow checker isn’t just useful for low level programming. One of the other main selling points is “fearless concurrency” or essentially the fact that the borrow checker can help you reason about thread safe vs non thread safe data.

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

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



Community stats

  • 3.9K

    Monthly active users

  • 1.7K

    Posts

  • 29K

    Comments