this post was submitted on 03 Oct 2024
34 points (100.0% liked)

Programming

423 readers
5 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

top 50 comments
sorted by: hot top controversial new old
[–] TehPers 36 points 1 month ago (3 children)

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

[–] robinm@programming.dev 29 points 1 month ago

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

[–] slacktoid@lemmy.ml 27 points 1 month ago (2 children)

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

[–] a1studmuffin@aussie.zone 12 points 1 month ago (1 children)

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

[–] Zink@programming.dev 7 points 1 month ago* (last edited 1 month ago)

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.

[–] TehPers 10 points 1 month ago* (last edited 1 month ago) (1 children)

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)

[–] slacktoid@lemmy.ml 10 points 1 month ago (1 children)

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.

[–] sukhmel@programming.dev 5 points 1 month ago (1 children)

Down that path C may become somewhat of an intermediate representation language for binary interfaces. No one would write it by hand, and maybe for the better

[–] bluGill@fedia.io 1 points 1 month ago

@sukhmel@programming.dev

@programming@programming.dev @modev@snac.bsd.cafe @TehPers@beehaw.org @slacktoid@lemmy.ml C is a terrible binary interface. It doesn't say who owns a pointer, or what to call to destroy it. It doesn't normally provide buffer length (even when it does there is no reason to trust it)

[–] QuazarOmega@lemy.lol 4 points 1 month ago

this was SO well written it was lowkey infuriating

[–] AsudoxDev@programming.dev 23 points 1 month ago* (last edited 1 month ago)

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?

[–] dudinax@programming.dev 19 points 1 month ago (2 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.

[–] Tja@programming.dev 2 points 1 month ago (2 children)
[–] dudinax@programming.dev 1 points 1 month ago
load more comments (1 replies)
[–] xigoi@lemmy.sdf.org 1 points 1 month ago* (last edited 1 month ago) (3 children)

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.

[–] dudinax@programming.dev 12 points 1 month ago

It also has real type safety and thread safety.

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.

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

Does it need more than the borrow checker if it's a game changer?

[–] lorty@lemmy.ml 16 points 1 month ago (2 children)

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

[–] GetOffMyLan@programming.dev 8 points 1 month 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"

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

All heil Rust-toad

[–] cbazero@programming.dev 16 points 1 month ago* (last edited 1 month 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++.

[–] mox@lemmy.sdf.org 9 points 1 month 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.

[–] arendjr@programming.dev 10 points 1 month ago* (last edited 1 month ago) (1 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.

[–] mox@lemmy.sdf.org 1 points 1 month ago (1 children)

Okay, but...

it’s clearly decided that Rust will be part of the future.

That's not what OP asked.

If you think Zig still has a chance at overtaking Rust though, that’s very much wishful thinking.

That's not what I said.

[–] arendjr@programming.dev 9 points 1 month ago* (last edited 1 month ago) (1 children)

No, OP asked for a black and white winner. I was elaborating because I don’t think it’s that black and white, but if you want a singular answer I think it should be clear: Rust.

[–] mox@lemmy.sdf.org 1 points 1 month ago* (last edited 1 month ago)

I see. You replied to me, though, with commentary that doesn't fit the question I was answering or the thoughts I was expressing. Don't you think it would have made more sense as a reply to OP?

[–] OpenStars@discuss.online 8 points 1 month ago (1 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.

[–] mox@lemmy.sdf.org 3 points 1 month ago (1 children)

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

Perl died because better tools became available.

[–] OpenStars@discuss.online 1 points 1 month ago (1 children)

Python is not better in every way, it's just more general-purpose, so has a wider range of applicability.

Also more people use it, though by that logic we should all be forced to use Windows bc everyone else does as well?

And Perl both still exists and is actively maintained, so it "lost prominence" rather than "died".

[–] mox@lemmy.sdf.org 2 points 1 month ago* (last edited 1 month ago) (1 children)

And Perl both still exists and is actively maintained, so it “lost prominence” rather than “died”.

Okay, but you're the one who called out "the demise of Perl". Have you changed your mind? I was just responding to your question.

For what it's worth, I think you were right about that: Perl is dead, in the sense of no longer growing or even maintaining the reach it once had. Other languages are overwhelmingly chosen for new code, while Perl has mostly fallen into disuse outside of people who learned it in its heyday and haven't moved on, and irrelevance outside of legacy systems. It might not be quite as much a dead language as Latin (which also still exists and sees some use) but it's well on its way there.

[–] OpenStars@discuss.online 1 points 1 month ago

Haha, oh yes, definitely not only not actively growing anymore but fully actively declining instead - those internal politics mattered more than the actual language issues themselves, once again. Every time I see another Python update and how very many things they break, I think that thought again. Tbf newer updates breaking older code happens even with C++ too - backwards compatibility affects just everything - though the whole Python 2 vs. 3 definitely still rankles me.

I guess I'm still having emotional trouble letting it go - but that is an absolutely perfect example of Latin, still spoken yet most definitely also considered "dead" at the same time. I guess this about sums it up:

img

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

[–] onlinepersona@programming.dev 8 points 1 month ago* (last edited 1 month ago)

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

[–] DmMacniel@feddit.org 6 points 1 month ago (1 children)

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

[–] G0ldenSp00n@lemmy.jacaranda.club 1 points 1 month ago (1 children)

Rust is named after the fungus, not oxidized metal

[–] vrek@programming.dev 2 points 1 month ago (1 children)

Python is named after Monty python and not the snake

[–] ICastFist@programming.dev 3 points 1 month ago

Brainfuck is named after... uh, something

[–] jeffhykin@lemm.ee 3 points 1 month ago

Why not both?

[–] BB_C@programming.dev 3 points 1 month ago (1 children)

I hope that someone in the 40 comments i don't have time to read right now has pointed out that the premise of OP is flawed for the simple reason that Rust hit v1.0 in 2015, while Zig is still nowhere near that milestone in 2024.

So we are not even talking about the same "future" period from the start.

So, no need to get to the second false premise in OP, which is limiting a "future" period to one successful dominating language only. Nor is there a need to go beyond these premises and discuss actual language details/features.

[–] BatmanAoD@programming.dev 2 points 1 month ago (1 children)

I also hope that some of the people reading this realize that OP is also the person posting all of the "stop trying to suppress C" posts.

[–] BB_C@programming.dev 2 points 1 month ago (1 children)

🤣

I don't know, and I don't want to get personal. But that's usually a sign of someone who doesn't even code (at non-trivial levels at least)*, and thinks programming languages are like sport clubs, developers are like players contracted to play for one and only one club, and every person in the internet gantry need to, for some reason, pick one club (and one club only) to be a fanboy of. Some people even center their whole personality around such fanboyism, and maybe even venture into fanaticism.

So each X vs Y language discussion in the mind of such a person is a pre-game or a pre-season discussion, where the game or season is an imaginary competition such people fully concoct in their minds, a competition that X or Y will eventually and decidedly "win".

* Maybe that was an exaggeration on my part. Some junior developers probably fall into these traps too, although one might expect, or maybe hope, that their view wouldn't be that detached from reality.


I'm hoping to finally finish and send out a delayed new release for one of my older and mature CLI tools this weekend. It's written in C btw 😄

[–] BatmanAoD@programming.dev 1 points 1 month ago

Modev says they've been using C for 25 years, and used Rust for several years as well! Their whole schtick baffles me.

[–] paw@feddit.org 2 points 1 month 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/

[–] 0x0@programming.dev 1 points 1 month ago

Rust introduces concepts from functional programming.

I'd rather go with Erlang.

[–] thingsiplay 2 points 1 month ago

Both. Why can't we have both?

load more comments
view more: next ›