5 ms·
Building a Rust Mentality
- ReactiveJelly 4y ago> If you ... look at questions surrounding the core principles of Rust—e.g. ... ‘why does Rust’s async implementation require boxing so often?’—you’ll soon find that a lot of these restrictions are a natural consequences of the design of the language I do find that satisfying, that "There is a reason for these restrictions" feeling. But, I can't remember the last time I boxed an async future. Maybe because I almost never use recursion. I'd like to see some of the author's code to see where boxing is used.
- indiv0 4y agoBecause there’s no async fn on traits yet, almost all “async” traits are returning Pin<Box<dyn Future<Output=T>>> under the hood. Same principle also applies if you’re trying to put a future in a struct (to create a named future). One of the fields will have more or less that type. This is useful for a few reasons (e.g. making it easy to refer to a specific future in type signatures or for writing futures out by hand).
- deleted 4y ago[deleted]
- superkuh 4y agoThe Rust mentality seems to be, "move fast, break things". The language features, and rustc itself, change so fast that a rustc released 3 months ago can't compile code written by someone of the Rust mentality written today.
- pjturpeau 4y agoI tried rust 4 years ago, and it was the case on a great extent. Is it really still true?
- deleted 4y ago[deleted]
- vlmutolo 4y agoWell this seems extremely misleading. Technically this is true: Rust doesn't have forward compatibility. But it does have guaranteed backwards compatibility since the 1.0 in 2015, which is far more important. So "break things" really doesn't apply. It's trivial to incorporate old code last written in 2015 into brand-new projects. And nowadays I'm not even seeing too many brand-new language features come out. GATs will land soon, but that really feels like filling out a part of the language that people would have expected to be there anyway.
- soneil 4y agoI heard they use the entire 'crates' repository as test-cases for breaking changes. If that's accurate, the backwards-compatibility is commendable. Forward-compatibility is near-impossible. Obviously it'd help if new code didn't use new features, but .. then why add them? How mature does a feature need to be before it's permitted to use them? How does a feature become mature if no-one's allowed to use it? etc.
- alpaca128 4y agoBackwards compatibility is guaranteed afaik, the rare breaking changes are activated by setting a newer Rust "edition" in the project's config. So in theory you can just keep coding Rust 1.0 style if you remove an auto-generated line that's used to set the project to the current 2021 edition.
- cesarb 4y ago> How mature does a feature need to be before it's permitted to use them? Each project has its own answer for that question; the acronym for it is MSRV (Minimum Supported Rust Version), and there's a field in the Cargo.toml for it ("rust-version"). It's not unusual to have the CI test the project with both the MSRV and the latest stable Rust version, to catch accidental use of new features. Unfortunately, there's as of yet no consensus on how to choose the MSRV. Some projects are more conservative ("the MSRV has to be at least one year old", "the MSRV is whatever comes with the oldest still supported LTS of Linux distros X and Y", "I set the MSRV once in the past and don't intend to increase it ever"), some projects are more aggressive ("we support only latest Rust and the previous one"), other projects are somewhere in the middle. (Edit: there's at the moment a very interesting discussion about the MSRV of the "libc" crate, which a lot of other crates depend on, and MSRV in general, at https://github.com/rust-lang/libs-team/issues/72 https://github.com/rust-lang/libs-team/issues/72)
- chrisoverzero 4y agoThat seems more like “move fast, add things”. I’m not sure how one could sensibly expect a compiler to be able to compile language features from the future.
- mustache_kimono 4y agoThis is pretty silly. I mean -- this happens, but this happens to any language, because as others have noted: forwards compatibility isn't a thing. New features will be added, and, given the track record of Rust, these new features have been pretty good! I recently experienced this relatively trivial issue -- I had only tested some software with the latest stable Rust version, 1.62. A user reported it was not building on the Ubuntu default installed 1.59, and I decided building on that version of Ubuntu was worth it. The fix? Install and use the relevant rust toolchain `rustup default 1.59`, `cargo check` points out exactly the issue (BTW the language change was a good change!), fix and push. It was so easy.
- duckerude 4y agoYou're getting flak for this, but you have a point. I wouldn't say it changes very fast. If you look at the language features in the past two releases they're all of the form "allow {existing feature} to do {thing you'd expect to be allowed}", and the library additions are minor. But it changes often, every six weeks, where e.g. Python releases features only once a year. And it's common practice to install new releases as soon as they come out without waiting for distros to pick them up. That means software starts depending on new features in minor frivolous ways that nevertheless break the build for older Rust versions. I make an effort to have my libraries support older Rust releases, but I have to go out of my way to check for compatibility. Not everybody does that, and it's unrealistic to expect everyone to—but with a different release schedule that would give fewer issues.
- mustache_kimono 4y ago> And it's common practice to install new releases as soon as they come out without waiting for distros to pick them up. That's the problem. It's not the release schedule that's the problem. The answer I've arrived at, right now, is to make the default version of the Ubuntu LTS release immediately prior to the latest, my default. Is that arbitrary? Yes. Might that change if some very cool Rust features are included in 1.64 -- like, if let chains? Yeah. So should the Rust community perhaps develop best practices on MSRV, at the very least notifying if a package deviates from MSRV norms? Maybe. Is this a big problem? Let's be real -- no, not really.
- tialaramex 4y agoWhat you'd expect, and what I think we see, is that over time the new features are less "must have" and so fewer programmers will chase the latest version. There's quite a gap between "Now arrays implement IntoIterator" (about a year ago, you can e.g. write for loops over an array) and "Termination is now stable" (May 2022, you can have custom exit code handling in your program) I'm sure a few people were excited about Termination, but practically everybody uses IntoIterator and arrays. So of course they would want that feature. As a Linux user I remember manually compiling 1.3.x back when odd numbered micro meant "Unstable" because 1.2 didn't have features I really cared about. Today I just run whatever kernel the OS installed. Are there important new Linux features in linux-next? Probably, maybe I will read about them in LWN and look forward to them, I'm definitely not going to bother compiling it by hand for any new feature I can imagine.
- duped 4y agoWhat are some examples?
- amelius 4y agoLet go of the Rust mentality.
- junofan 4y agoI am fairly tired of Rust devs and boosters monopolizing online spaces. There was a Zig article the other day with comments that derailed into Reasons For The Rust Way. IMHO this behavior is not helpful for PL experimentation and adoption.
- mustache_kimono 4y agoI think this is fair. On the other hand, I think the flimsy arguments ("Just write better code..." and "Modern C++ doesn't have these issues..."), the mole hill matters of taste ("Egads! The syntax!" not "I think Swift does this better for the following reason..."), and the drive by hype hate, are just as tiresome from the anti-Rust crowd.
- woodruffw 4y agoI'm admittedly a Rust booster (in the sense that I like it) and so perhaps I'm biased, but: I don't really see Rust monopolizing spaces that don't otherwise make sense? HN has a pre-existing bias towards the newest and shiniest thing, so it's not surprising that Rust takes up a lot of the oxygen in PL conversations (especially when so many of its peers, like Zig, emphasize having fewer deviations as an advantage.) But I don't see Rust taking up a disproportionate amount of headspace in more focused technical communities.
- avian 4y agoIt's not just discussions about programming languages. All kinds of HN posts about security vulnerabilities commonly get sidetracked by very predictable "if only it would be written in Rust" threads.
- woodruffw 4y agoI guess I don't understand how that qualifies as "sidetracking." If the vulnerability in question is a spatial or temporal memory safety bug, it seems very reasonable and pertinent to observe that Rust would have prevented it. Unless it's the volume or consistency of that reply that you're objecting to?
- PointyFluff 4y agoI'm assuming that was an ad-filled blog. (uBlock Origin) Because content wise there was almost nothing in this article.