by agumonkey · 7y ago · 0 comments
A common pattern to mitigate this (though not always applicable) is a generic trampoline to a monomorphic function for the cases where the genericity is mostly a matter of convenience e.g. let's say that your function works on strings, but for convenience you take a `T: AsRef<str>` (callers can pass anything from which a string reference can be created cheaply), the first thing you do is `let s = s.as_ref()` so the vast majority of the function is monomorphic (it takes only one set of concrete types as input). Rather than this:
fn my_function(s: T) where T: AsRef<str> {
let s = s.as_ref();
// do stuff with s: &str
}
you can do this: fn my_function(s: T) where T: AsRef<str> {
_my_function(s.as_ref());
}
fn _my_function(s: &str) {
// do stuff with s
}
unless rustc decides to inline just _my_function into my_function (which would be quite odd), this leads to very little monomorphization and bloat.I think the biggest issues are reliance on cargo (the systems language that ignores your system libraries) and lack of a stable ABI, this is why it will never replace C. Many people find the borrow checker aggravating. Even rust fans seem to find the compile times far too long. As with all languages some will find it too high level and others too low level, should it throw exceptions or should it use error codes, etc.
And let's not forget the rust fans brigading any disagreement.
edit - do you mean in general or for this specific issue on the LKML, my reply assumed in general.
It's still pretty new, but it's gaining adoption quicker than what I would have expected. It's now used in Google, Facebook, Amazon, Dropbox and Microsoft. Most of the time it's for some niche or experimental project, but it's still an interesting trend.
> I think the biggest issues are reliance on cargo (the systems language that ignores your system libraries)
This is not accurate. There is no "reliance" on cargo, you can just use plain rustc and it would work. And you can of course link dynamically to a system's library: by default Rust's binaries are even linked with the system's libc actually, and AFAIK most external C dependencies are linked that way (bindings to openSSL for instance).
> and lack of a stable ABI
Many people would love to have a stable ABI, but it's way too early for that because it would freeze Rust development, while there are still a lot of things that need to be improved in the language.
I agree with you on compile times though and I hope things continue to improve in that regard.
Basically that's what I was trying to say but failed somehow.
Rust doesn't have recoverable exceptions. It has fancy error codes. It is also quite low level in the same spirit as C++: only pay for what you use, and what you use should not be possible to write more efficiently by hand.
Playing devil's advocate: when compiled with panic=unwind, it has. However, the fact that when compiled with panic=abort they turn into unrecoverable exceptions tends to make the "should it throw exceptions or should it use error codes" choice clear.
In Rust, you'd use Result where in C++ you would use exceptions.
Panic is equivalent to assert and should not be used where you'd use exceptions in other languages.
FWIW I had been hearing buzz about Rust from the community that I work with regularly (including the occasional "I'm working on rewriting $COMPONENT in Rust") long before I started frequenting HN.
You hear "X is good" from 7-8 people. You dismiss these people as fans lacking objectivity.
If you now hear "X has shortcomings" from 2-3 other people, do you now tell yourself "Yes I knew it all along. X isn't as good as the fans said it was" or do you think "Yeah, now that I have other opinions I can say that the majority of people think X is good and therefore it's probably good".
If it's the first, that's just confirmation bias. If it's the second, that's better but I don't get it - why does the mere presence of a contradicting opinion make the first opinion more valid?
In any case wouldn't you be better off trying X first hand and forming your own opinion?
To expand what I mean, when I recall what I have seen people say on Rust, some things strike me: overwhelming positivity, lack of depth, and it-cures-all-ills.
In a word, hype.
I don't owe anyone my attention to do some determination about how valid this or any other hype is.
If I hear people talking about something and the loudest and most numerous voices are hype, I think it is fair and rational to have a solid doubtful bias much moreso than if conversation seemed more varied, substantial, and rational.
Things that attract more rational people than hype-r people correlate with quality.
There are bad projects with a lot of hype, bad projects with little hype, good project with little hype and good project with a big hype. Hype just isn't a good proxy for quality.
But hype is often a good proxy for success though: no matter how good your product/techno is, it's going to fail if there is no traction. Overall, if you think a product is good, it's good news if there is hype about it also. (And I think it's exactly what's happening with Rust: a good tool with a good amount of traction. But yeah, fanatics are always boring)
What makes people excited about Rust is not that it's perfect right now, nor do people claim that it's perfect. They're excited because they've seen a lot of progress in the last 3 years and see a clear path for it to become better in the next 3.
Almost every blog post I've read mentions shortcomings. Take one I read today from way back in 2017 (showing that people criticising Rust is not new) - https://onesignal.com/blog/rust-at-onesignal/. While they are very happy with their choice, they mention
1. Build times being very long. This is partly the fault of rustc generating verbose LLVM IR and partly because of code-gen macros like the ones used by serde (the crate that makes json parsing easy)
2. Libraries such as async clients for postgres and redis not being available. Http clients being immature and having to spend time improving them.
3. IDE experience being poor.
Of course, 2.5 years later many of these issues are no longer true.
* Build times have improved a 8-30% depending on the project in 2019 (https://blog.mozilla.org/nnethercote/2019/07/25/the-rust-com...). Incremental builds are a thing now, as are check builds (they generate no artifact, just make sure your code is compilable).
* Many more libraries available. Certainly all the basics will be covered once async-await becomes stable and all network libraries add support for it.
* RLS is reasonably good, IntelliJ-Rust is better and rust-analyzer is being worked on. Current situation is much better than the days of using Racer and will likely improve within 2 years when rust-analyzer is mature.
So there you go - an example of a Rust "fan" pointing out it's shortcomings 2.5 years ago, and the ways in which Rust has improved since then.
If your issue is that you see Rust being mentioned by fans a lot, it's likely because we keep reading stories about vulnerabilities that happen over and over, issues that wouldn't exist in a Rust code base. If these vulnerabilities were less common, maybe we wouldn't see Rust being mentioned so much.
That's because the primary (and so far only) use for Rust is as an excuse to avoid learning C++.
Nobody actually writes real software in it.
As you doubtless already know, the programming language everybody likes is a programming language nobody uses.