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

I’d say if you’re happy with #C, there’s no need to choose any second language. 🤷

Before even looking at any alternatives, the question should be “why not C”. Some of the typical complaints are:

  • memory safety – or, more generally, the fact that C is only partially defined, leaving a lot to the dangerous area of undefined behavior. There’s no way to reliably detect undefined behavior by static code analysis, and it will often hide well at runtime. Especially errors regarding memory management often directly expose security vulnerabilities. In my experience, the risk can be reduced a lot by some good coding and design practices. Examples are avoiding magic numbers, using sizeof everywhere possible, preferably on expressions instead of type names, defining clear ownership of allocated objects (and, where not possible, add manual reference counting), making ownership explicit by using const where appropriate and naming your functions well, and so on. Given also there’s no guarantee alternative languages will safeguard you from all the possible issues and there are also a lot of other ways to create security vulnerabilities, my take on this would be: partially valid.
  • programming paradigm – you can only program in classic procedural style. Well, that’s simply not true. First of all, you can program whatever you want in any turing-complete language, so what we talk about shouldn’t be what’s directly supported by the constructs of the language, but what’s practically usable. In C, using some simple OOP is commonplace. Well, you can apply OOP to assembler programming without too much hassle, so, it’s not surprising you can do it in C, as it’s a pretty thin abstraction on top of machine code. C helps further with its linkage rules, where everything in a compilation unit is by default inaccessible to other units, and its incomplete types, where only a type name is known, but neither its size nor inner structure, giving you almost perfect information hiding for free. If you want/need polymorphism, it gets a bit more complicated (you have to think about how you identify types and manage virtual tables for them), but still perfectly doable. You’ll hit the practical limits of the language when you want to go functional. The very basics are possible through function pointers, but most concepts of functional programming can’t be applied to C in a somewhat sane way. Unless that’s what you need, my take would be: invalid.
  • limited standard lib. Indeed, the C standard library misses lots of things that are often needed, for example generic containers like lists, hashtables, queues, etc. It’s straight-forward to build them yourself, but then, there are many ways to do that (with pros and cons). You’ll find tons of different implementations, many non-trivial libraries bring their own, of course this also increases the risk to run into buggy ones … I wouldn’t consider it a showstopper, but I’d mark this complaint as: valid.

Then, the next question would be: For what purpose are you looking for a second language?

For applications and services, there’s already a wide range of languages used, and I’d say do what everyone does and pick what you’re most comfortable with and/or think best suits the job. IOW, it makes little sense to ask what would be “the future”, there have always been many different languages used, just pick one that’s unlikely to quickly disappear again, so you’d have to restart from scratch.

For systems programming “the future” has been C for many decades 😏 … some people want to change that, actually for good reasons. IMHO, the current push for #Rust (I don’t see anything similar regarding #Zig yet?) into established operating systems is dangerous. An operating system is very different from individual apps and services. It’s required by these as a reliable and stable (in terms of no breaking changes) platform. It’s complex and evolves over an extremely long period of time. It needs to interface with all sorts of hardware using all sorts of machine mechanisms (PIO, DMA, MMIO, etc pp). I conclude it needs a very stable, proven and durable programming language. You’ll find C code from the 30 years ago that just still builds and works. IMHO a key factor is that there’s an international standard for the C language, governed by a standards body that isn’t controlled by any individual group. And correlated to that, there are many different implementations of the language. Before considering any different language in core areas of an established operating system, I’d like to see similar for that new language.

Now, C was developed more or less together with #Unix, so back then, nobody knew it would be such a success, of course there was no standard yet. But then, I think this is the sane way to introduce a new systems programming language: Use it in a new (research?) OS.

permalink
report
reply
1 point

Thank you for such extended answer, I appreciate it.
Thank you for your experience!

permalink
report
parent
reply
2 points

Check Redox

permalink
report
parent
reply

Nice, that looks like the way to do it!

“Funny” how it even offers a libc for compatibility … but I guess this helps getting it some more serious testing 😉

permalink
report
parent
reply
7 points

For me you really aren’t selling it.

When the answer to major draw backs with a language is use it better that’s a dead end for me.

Some of the greatest programming minds have been using c for a long time and we still have a huge amount of dangerous vulnerabilities all the time.

The language is fundamentally flawed and other languages have demonstrated that you can get the same flexibility, expressiveness and performance without these flaws.

Again with the lack of many standard lib constructs. I now have to trust that every lib i use was written by a serious expert. as they’ll need to implement so much themselves rather than trusting the core language team, who you hope would know it better than most.

And again with OOP. Why hack it into a language rather than use a language that supports it.

It’s beginning to feel like people are just clinging to c because it’s what they are used to. All I seem see are justifications of its flaws and not any reasons to actually use it.

If it came out today you’d have an incredibly hard time convincing anyone to use it over other languages.

permalink
report
parent
reply

When the answer to major draw backs with a language is use it better that’s a dead end for me.

Try browsing the list of somewhat recent #CVE rated critical, as I just did to verify. A majority of them is not related to any memory errors. Will you tell all them “just use a different programming language”?

And again with OOP. Why hack it into a language rather than use a language that supports it.

Have you seen existing C code? For anything non-trivial, most code uses some OOP, and it comes quite natural in C, certainly no “hacking”. You don’t need a class keyword to do that.

If it came out today you’d have an incredibly hard time convincing anyone to use it over other languages.

It doesn’t come out today, it’s been there for a long time, and it’s standardized, proven and stable. Sounds like you seriously misunderstood my points, which were, in a nutshell: For applications and similar, just use whatever suits you; for operating systems do experiments in lab/research projects (as was done with Unix), because existing and established ones are relied upon by lots of software. Just to make that perfectly clear, that doesn’t mean they should use C forever, it means they should wait for a potential replacement to reach a similar state of stability with independent standards and competing implementations.

permalink
report
parent
reply
6 points

Try browsing the list of somewhat recent #CVE rated critical, as I just did to verify. A majority of them is not related to any memory errors. Will you tell all them “just use a different programming language”?

I’m sorry, but this has been repeatedly refuted:

And yes, they are telling their engineers to use a different programming language. In fact, even the NSA is saying exactly that: https://www.nsa.gov/Press-Room/News-Highlights/Article/Article/3215760/nsa-releases-guidance-on-how-to-protect-against-software-memory-safety-issues/

It doesn’t come out today, it’s been there for a long time, and it’s standardized, proven and stable.

This seems like an extremely short-sighted red herring. C has so many gaps in its specification, because it has no problem defining things as “undefined behavior” or “implementation defined”, that the standard is essentially useless for kernel-level programming. The Linux kernel is written in C and used to only build with GCC. Now it builds with GCC and LLVM, and it relies on many non-standard compiler extensions for each. The effort to add support for LLVM took them 10 years. That’s 10 years for a migration from C to C. Ask yourself: how is that possible if the language is so well standardized?

permalink
report
parent
reply
7 points

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.

permalink
report
reply
13 points
*

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.

permalink
report
parent
reply
-3 points

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.

permalink
report
parent
reply
10 points
*

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.

permalink
report
parent
reply
9 points

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.

permalink
report
reply
4 points

the demise of Perl

You imply this is a bad thing

permalink
report
parent
reply
2 points

I have never quite understood this mode of thinking - I think it must be an imprecise statement. Yes, improper usage of Perl coding can be bad, but then so too can C/C++ with e.g. improper memory management? Yet, I don’t see people knocking down doors to learn the memory-safe Rust (and e.g. thereby be able to contribute to the Lemmy codebase), probably bc despite it being “better”, it also has a steep learning curve (and I don’t even know but I would assume: even for someone who already knows C?). Instead, people seem to want to learn Go, or Java - okay so that’s a rabbit hole b/c they are for entirely different purposes, but anyway I mean that each language has its own balance of trade-offs.

So while on the one hand the worst-case scenario from a poor coder for Perl seems significantly worse than for Python, there are also benefits too: doesn’t Perl run up to 20x faster than Python, which is why many places e.g. booking.com have chosen to use it? In the hands of an experienced person, perl code is quite readable, while in contrast, I just absolutely HATE aspects of Python such as whitespace delimiting and the package management, plus I don’t know if I am imagining things (is is likely) but the code just seems to me to look obtuse, by comparison.

Sometimes I’ll use awk, other times I’ll bump that up to a Perl one-liner or even full script, still other times demand Python or for number-crunching full C/C++, or Java for whatever reason, but… for things that you want fast & easy, I don’t really see Perl as “bad”? Granted, it shouldn’t be someone’s first language these days, compared to C or Python, but what is wrong with it, like awk, continuing to exist these days? Especially if it’s not in a production environment.

I’m listening.

permalink
report
parent
reply
6 points

Collaboration is a fact of life in software development.

Therefore we must choose tools based not on a single developer’s preference, but by what their colleagues can use effectively.

  • Tools that are easy to write bugs with (C/C++)
  • Tools that are hard to learn (Perl)
  • Tools that are hard to hire for (Perl, Ruby)

All of these should be fixed or shunned in favor of languages that are easier to hire, easier to learn, and easier to debug.

permalink
report
parent
reply
3 points

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

Perl died because better tools became available.

permalink
report
parent
reply
1 point

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

permalink
report
parent
reply
2 points
*

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.

permalink
report
parent
reply
15 points

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

permalink
report
reply
1 point

All heil Rust-toad

permalink
report
parent
reply
9 points

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”

permalink
report
parent
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

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