157 points · by amaccuish · 7y ago · 245 comments
Now, we add Rust to the list. You can write that library in Rust and it can be used by anyone, too. That's because there is no GC or other extraneous code, and because you can make structures with specifically-defined layout in memory.
Making a list of options go from two to three is a big deal. Especially when, a lot of the time, C++ ends up looking like C when you need to interface it with something else. So Rust is kind of like going from one to two optons.
I'm ignoring other good languages, I know, but those are often just not chosen for a variety of reasons. Rust seems to be breaking out of that trap because of a good community, a few nice features, the fact that it's new, and a bit of luck.
Also, such interfaces generally require more copying around of structures to match the format the language is expecting. With rust, it can use plain C structs directly without translation.
With Windows 8, it got a new facelift (WinRT, UAP, UWP) and the large majority of Win32 APIs are as they were in Windows 7.
Anyone doing modern Windows development, has to use COM in some form.
Genuine question: Can you link a Rust binary with a C/C++ binary?
Notably you need to use the C ABI to call things from C++ as Rust FFI doesn't support C++ directly.
Then when it loads a .h, hash it, and if the hash is unchanged don't write anything. This way, the cargo/rust incremental compilation does the rest of the work. Minimal change to how it works now, yet the compile times go way down.
If you are willing to live dangerously, you could always use modification times instead of hashes to avoid having to even read the .h files on compile, but frankly that sounds like it'd just make enough heisenbugs that people would start doing clean compiles just in case.
Rust fills a niche. It's not the answer to everything.
The learning curve is steep, and for many applications, the benefits are nonexistent.
Although you can use Rust (or anything, even Bash if that's your thing) to write web applications, Ruby, Python, PHP and Javascript are far more productive and this is not going to change tomorrow.
Rust's borrow checker doesn't add anything besides complexity here.
Go is also a nice balance between being simple to use and powerful as a system language (unless "has no GC" is how you define a system language).
Swift has most of the best parts from the language above.
Crystal is a pleasure to write and runs fast.
Zig may eventually get more traction.
Something like Rust, but accessible, readable, that compiles quickly, is stable and has a natural way to do async operations could quickly make Rust obsolete.
I am not sure how much Rust you have done yet, but the borrow checker is a tremendous confidence booster. Especially refactoring code. I have never had anything where I can feel at ease in making big changes to an existing code base. As all things, I don't think you notice it once you learn how to write safe Rust code.
Go is certainly a good balance. One of its best things is the rich standard library. I wish Rust took more of that approach.
One thing about Rust that is maybe overlooked is that it is, like C/C++, truly "full-stack". By that I mean you can go from low level embedded (microcontroller with no MMU) all the way up to web server, etc. I don't think it is really a "niche" language--at least it has a very horizontal use case.
Having been at this for a super long time, I have seen the popularity languages come and go from ASM, Perl, Java, Python, .Net, etc. I can assure you nothing is gonna "quickly" make another language obsolete. New languages are incredibly hard to get off the ground and be relevant for a long time.
At some point the friction just grew too hard and I said to myself: "Ok you stupid Rust, I will do it your way, I just want this to work" and then it made click and everything fell into place – builder patterns, traits, composition over inheritence – I realized that clinging to all the patterns I had learned was idiotic, because Rust has given me maybe even more powerful ways of expressing myself.
If it wasn't for the friendly Compiler yelling at me, I doubt I would've gotten so far.
Man of us are already competent in C and/or C++, so to make a move there has to be a big value prop if it's a large investment. I'm not saying there's not, but most of us aren't deciding to pick up C, C++ or Rust from scratch.
On a personal note, learning Rust has made me a much better C++ developer. I'm more conscious of various degrees of aliasing and multiple ownership, to the point where much of the C++ I've written of late is inspired by the borrow checker's conventions. And since what I do is usually executed concurrently, I've seen a concrete decrease in bug count and severity without cost in performance. Which means the time investment in learning Rust has paid off, in my opinion.
But that being said, when you see that the majority of vulnerabilities are essentially memory lifetime issues (https://msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe...), you realize that we are all human. So something like Rust could help--especially new developers.
I recently spent an entire week diving into Rust for a personal project. While it certainly had a learning curve that slowed me down (particularly regarding the borrow checker), I realized that I only had 1(!) runtime error all week...in a language I was unfamiliar with. That gave me a huge amount of confidence in memory safety.
Even though I love golang and use it daily for my job, I'd suggest that golang is not a good fit for Triplett's definition for systems programming.
Also compilers, runtimes, GCs, databases, cloud schedulers (Kubernetes etc) are also not 'apps' could fit in systems programing definition.
Crystal has no support for parallel execution, which is an important feature nowadays, at least, when one compares it to Go and so on.
However I'm excited for the future of system-level programming: we were stuck with C/C++ for a long, long time and maybe that's finally changing thanks to Rust!
In the system programming world, "simple" means having the program do what you tell it and no more, so that there are no surprises when you come to run it.
Rust has a very complicated compiler, and a moderately complicated syntax, but the semantics of the language are amongst the simplest out there - far simpler than C (purely because of the UB), Nim or Kotlin Native IMO, and that really helps when writing low-level code, or even just when contributing to an unfamiliar code-base.
There's nothing simple about Rust.
The compiler is complex and slow.
The borrower semantics is anything but simple.
It isn't uncommon for the syntax to look arcane.
The standard library is shallow often making developers have to resort to third party libraries for trivial things.
Rust improved upon languages like Cyclone but it's a far cry from being the next C/C++ when it comes to potential market adoption.
That said: almost all your points apply to C++.
There's nothing simple about C++.
it can be incredibly complex and slow (though faster than Rust, but that's not much of an achievement).
The rules around what constitutes valid (non-UB) code is anything but simple.
It isn't uncommon for the syntax to look arcane (IMO much more so than Rust, although obviously YMMV).
The standard library is extremely shallow, making developers have to resort to third party libraries for trivial things, except there's no package manager or standard build system, so good luck with that.
And yet, here we are, with C++ dominating the market. So I don't think any of those reasons are dealbreakers at all.
I believe Rust has the potential for market adoption as a serious C++ competitor. It still has a long road to get there, but C++ didn't reach this point in a day either. We see more and more adoption in big companies of Rust. Microsoft recently expressed interest in using rust in critical components to reduce security bugs for instance. More and more companies are experimenting with Rust, and some are even using it in production.
Besides, there's another victory to Rust: more and more languages are looking into integrating borrow semantics in their own language, like swift[0]. This is proof that Rust's core ideas work. If those trickle down to other languages, the "complexity" of borrows will probably become just one of the other things you just have to get used to to learn programming.
[0]: https://github.com/apple/swift/blob/master/docs/OwnershipMan...
I keep seeing people saying this when discussing Rust in relation to C++. It's not untrue, but I would counter by saying that people who were writing C++ without having a full understanding of ownership and lifetime semantics were writing buggy code. Rust just makes understanding those semantics required to get your code to compile.
I'd rather have a thriving and single (looking at you Python) ecosystem of third-party packages, than a standards-driven pile-on of standard libraries, with all the footguns and deprecation that tends to come with it.
It doesn't mean that the language is complex.
> The borrower semantics is anything but simple.
The borrow checker doesn't change the meaning of the program in any way. You can perfectly understand Rust code without any knowledge of the borrow checker (there is a working Rust compiler that doesn't even have a borrow checker), so it cannot make the semantics of the language more complicated.
> It isn't uncommon for the syntax to look arcane.
Again, I did call out the syntax has being moderately complicated. The great thing about syntax is that it's superficial. Syntax has to be pretty bad to continue being an issue beyond the initial stages of learning a language, and I don't think Rust's syntax is close to being that bad, it just has some unfamiliar elements to a lot of people.
> The standard library is shallow often making developers have to resort to third party libraries for trivial things.
This sits on the "Rust is simple" side.
> Rust improved upon languages like Cyclone but it's a far cry from being the next C/C++ when it comes to potential market adoption.
In terms of actual market adoption I'd agree. But you said potential market adoption, so I don't.
I was with you till this point. Rust is ugly, complex, but far batter that C++ in this regards.
* Functions instead of 666 constructors with obscure rules of which you should implement in pairs
* Hygienic macros instead of that ugly unsafe mess in C and C++ called macro and templates
* Move by default and Copy by calling a copy() function
* Everything is so explicit
But the best parts of Rust are its move semantics, enum datatypes and traits, everything that makes programs a joy to express.
>but it's a far cry from being the next C/C++ when it comes to potential market adoption.
Because C++ is very similarly complex/arcane etc.
("Modern" JavaScript comes close, but that's not because of semantics, it's more because everything is incredibly overengineered...
The big borrow checker hurdle comes from developers not being used to thinking in/about lifetimes. It takes some getting used to because it enforces constraints that should be there for a non-GC language, but are not enforced anywhere else. But it is a hurdle you can get over after a few weeks of feeling like an idiot. At one point it just clicks. You start to design your types and code with lifetimes in mind, and the borrow checker is not a problem anymore and feels natural - and a helpful safeguard even.
The other complex part is the lack of inheritance and the trait system, which is also foreign for many. I feel like if you had contact with ML languages, and Haskell in particular, you will have a much easier time. It takes a different approach for structuring code.
Sadly Rust is in fact getting mroe more complex all the time though, with things like async/await added and other complex features in the pipeline (like specialization, higher kinded types, generators, ...).
All of those make sense and make the language more powerful, but at the expense of simplicity.
That's not the case for Rust. It takes a few solid weeks of feeling stupid until you really start to grasp borrowing, and that experience may feel offensive to people who are used to knowing what they're doing, but a few weeks really isn't that much time in the grand scheme of things.
That's a typical experience, but it's not because Rust is that complicated, but because it's different.
People approach Rust with their intuition from other languages, such as C's or Java's where you can have a web of objects referencing each other willy-nilly, and are stumped by Rust's insistence on clear, single ownership, and simpler tree/DAG-like structure of program's data.
Single ownership itself is simple, you just need to unlearn multiple-shared-ownership habits.
The syntax is strict, but this avoids some bugs that would have taken time to spot at runtime.
For some use cases, this is a time saver. For everything else, you may spend more time fighting the compiler than you would have done debugging these issues afterwards.
But yeah, it's a language that constantly makes you feel stupid. The compiler is barfing errors that are hard to understand, for code that looks trivial.
More complicated than Haskell, etc.?
That is not necessarily true. Not sure in the case of Nim or Kotlin Native, but the GC itself can be written in Nim/Kotlin Native in principle as well.
It's not a crazy idea. Go actually works that way already; the runtime of Go is implemented in Go. For example, here's the sweeping component of the gc: https://github.com/golang/go/blob/master/src/runtime/mgcswee... But that doesn't mean you can get a Go without a runtime; the final executable's GC may have come from compiled Go rather than something else, but it still irreducibly has GC in it. The whole thing is bootstrapped, so at any given time when some bit of Go code is running, it is supported by GC and the rest of the non-optional runtime, even when compiling code that itself is going to be the runtime of some other executable in the future.
[1]: https://ziglang.org
The fact that Mozilla was behind Rust played a lot in Rust becoming popular.
But a lot of nice languages have stayed under the radar, and have been eventually abandoned.
To succeed, Zig needs maturity, but also marketing. And that is hard without some big name advocating it.
I've seen ppl say that something seems amiss with the V project.
That are trying to get into the C replacement business.
In that sense Rust does seem very interesting.
At least the Rust subreddit figured out that there's this other language which fulfills the same requirements of being a higher level C, except unlike Rust it has a massive ecosystem, mind share and vendor support - including from Intel. It does have worse PR, but this is mostly because Rust is unbeatable here.
It would be interesting to also hear from Josh's colleagues which work on a large number of C and C++ projects. Do they agree that Rust is the future? And does that mean that all of Intel's money-making software is essentially obsolete? Is Intel the company aware of that?
Which language are you talking about? C++?
I'm still not sure what type of applications to use it for to be honest- not having good support for embedded systems and no CUDA/OpenCL support makes it not appealing.
This is not strictly true. Most Rust programs, like most c programs, do have a runtime. See https://doc.rust-lang.org/0.12.0/guide-runtime.html
However, this runtime can be replaced which is what makes Rust suitable for certain systems programming scenarios (like building operating system kernels). This is the realm of [no_std]
You've linked to the docs of a release from 2014, back when Rust did have a runtime.
(Unfortunately it's very easy to get results for ancient Rust releases from search engines. Similarly there are three different versions of the Rust book and many of the search results are for the oldest one.)
>However, this runtime can be replaced which is what makes Rust suitable for certain systems programming scenarios (like building operating system kernels). This is the realm of [no_std]
What `no_std` allows you to do is not use libstd, ie the standard library. libstd is certainly a "runtime" in the sense that libc is the C runtime, but it doesn't mean it enforces green threading or garbage collection like the word "runtime" evokes for other languages and is used in the page you linked. This latter meaning is also what the sentence in the TFA was using.
1. Your link is incorrect, as the sibling comments say, but you're also correct that Rust has a runtime. It's about the same amount of runtime as C, but like C (as you say), it does exist.
2. no_std does not remove the runtime. I think the closest you can get is no_core, but to be honest, I'm not actually 100% sure.
edit/sorry?
Or, maybe Rust semantics with Python’s readability? I would like that. Rust is the wave of the future, but ultimately the language will not be a long-term survivor, entirely because of the ASCII-salad syntax. I predict that we will learn huge amounts about language semantics from Rust, thank the team, and then replace it with something pleasant to read.
Rust is the Algol of a new generation. I mean that as both high praise and as a sad prophecy.
impl< $($kind: TryFrom< Value >,)* F > allMut< ($($kind,)*) > + 'static, F::Output:
There is https://pyo3.rs/v0.7.0/
>Rust is the wave of the future, but ultimately the language will not be a long-term survivor, entirely because of the ASCII-salad syntax.
I can agree with that. Hence Rython.
Rust is certainly the future when compared to C or C++.
From what little I have done with Cython, you done really see the C compiler much. Just the data types. Rython would still have the Python garbage collector ultimately “owning” all the variables, though, I think.
Memory safety and automatic memory management come at a cost. Even in Rust. C will always have a use for critical performance in the embedded world.
Based off of what reasoning? It's not like C is any faster or more efficient than Rust or C++. Heck you can often go faster in C++/Rust than you can in C thanks to the ease of using abstractions that just make things go-faster for you automatically (such as SSO in things like strings, or constexpr for compile-time resolution).
The embedded world isn't using C because it's a good fit, they are using it because of legacy inertia and lack of motivation to move to anything else. IoT is starting to change that, as all those C memory vulnerability issues turn into product support costs.
And also realistically embedded isn't even restricted to C already. Very popular microcontrollers like the esp8266 or esp32 also have javascript runtimes.
Huh? C is certainly faster than C++.
go-faster for you automatically (such as SSO in things like strings, or constexpr for compile-time resolution).
That is a terrible example. You shouldn't be using the STL (i.e. std::string copying) for performance critical sections to begin with.
Very popular microcontrollers like the esp8266 or esp32 also have javascript runtimes.
First, esps are not low end microcontrollers at all. Second, no one uses JS runtimes for performance critical code on microcontrollers (e.g. JS will not give you direct memory access). What an absurd claim.
It literally isn't. Quite often the reverse is true, as C++ gives you better tools for compile-time optimizations.
> That is a terrible example. You shouldn't be using the STL (i.e. std::string copying) for performance critical sections to begin with.
I think you're confusing the example with a recommendation to use the STL?
std::string is just an example of SSO. The concept is generally applicable and used in more places than just the STL.
Although "You shouldn't be using the STL for performance critical sections to begin with." is also complete fucking bullshit anyway. There's nothing wrong with the performance of eg std::array. Or unique_ptr. Or vector. Or a variety of other things in the STL. You're not outperforming any of those with raw C.
It's not 2003 anymore so stop acting like it.
I am somebody who uses C on embedded but really likes the way Rust does things too. Sometimes my naive Rust implementations outperformed my optimized C code very easilly (maybe I am not good enough, who knows). What I especially liked are the zero cost abstractions, which allows you to keep that cost you were talking about very low.
And if I like to do stuff on my own I just do it inside an unsafe block and I am very close to what I could/would do in C.
Even if Rust would fade away it teached me a few hard lessons that definitly improved my C programming.
C has been declared dead and replaced so many times over the years that I have lost count. It is not going to be replaced enitrely by Rust, and definitely not in the embedded world. C will not be the new assembly, it will continue to be C.
C++ could be an entirely different story.
Assembly is bad because it is typeless. Because it is typeless, there is no way to check for program correctness. Rust is okay because it doesn't require garbage collection and types, but the best language would be C with a highly-elaborate strong type system and no closures or other unsuitable concepts for systems programming.
I once was working with libpurple in a glib environment that made heavy use of segfaults in C. I mean closures. Closures in C that made it really easy to segfault when calling to a closure that had been freed, or really easy to leak if you didn't free them. I encountered situations where the common paths used by the "standard UI" for libpurple worked, but even when I was quite sure I was handling one of my closures correctly, the system would crash because it still free'd my closure, even though it should have been my responsibility to do so, and so on.
Prior to Rust, I'd agree with the common wisdom that closures and systems programming had gone together poorly. It's a demonstration of the power of Rust's approach to the matter that closures become practical in system programming with it; that had not previously been the case.
(0..1000).map(|x| x*2).sum()
compiles to mov eax, 999000
Rust takes full advantage of its ownership, mutability, lifetime tracking and generics to have closures with zero overhead.For reference: https://twitter.com/bascule/status/1166583003021283333
Since you commented "I don't actually care about Rust, I'm only farming karma to downvote posts on this trash news aggregator", I hope your bad faith attempt to spread FUD fails.
It's a big if---especially adoption---but it makes sense to me.
* Make it harder to publish
* Make it easier to find quality packages
I'd prefer the latter.
* Have every single common thing live in a standard library which makes them stagnate, slows down language development and so on.
* Have people roll their own half-baked, half-broken code every time.
I stand firmly that big organic ecosystem of packages and thin library is the right way, and all we need is just better tools to manage trust and quality.
In the end you need gatekeeping. That's a security-critical function, and it's a people function, not a function of language.
I agree that the dependency problem is getting continuously worse though. An important factor is people splitting up crates into multiple sub-crates, proc macro crates (which have to live in a separate crate), and generally having a much too cavalier attitude about adding dependencies.
The last year has been particularly bad, but on the flip side there is also increased awareness and motivation to counter this.
Rust will never have a stdlib like Go, with http server/client, compression and crypto algorithms, ...
But I do think that it needs to be conservatively extended with some core primitives that are missing. A problem is the still heavily evolving language. A few upcoming features could change idiomatic API design, so putting anything in std now could be a big mistake in the long term.
I admit - Rust is on the easier side of packaging, which tends towards proliferation of dependencies, but the general feeling I get right now from rust communities is a deliberate restraint when it comes to dependencies.