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.
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.
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:
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 usingconst
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.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.
Check Redox
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 😉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.
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”?
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.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.
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/
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?
Thank you for such extended answer, I appreciate it.
Thank you for your experience!