Live data from Hacker News

Why asynchronous Rust doesn't work

theta.eu.org

11–20 of 499 posts

Re: Why asynchronous Rust doesn't work

#11

I'm surprised Rust went with a Scala-inspired async/await considering it wasn't well-liked outside of PLT enthusiasts. JavaScript adopted it as I don't think you could bolt any other type of sugar on top of the event loop in browsers... but Rust shouldn't suffer from such baggage.

Do you have a source on people generally disliking async/await? I've become a fan of it in JS.

Re: Why asynchronous Rust doesn't work

#12

> The thing I really want to try and get across here is that *Rust is not a language where first-class functions are ergonomic.* So... don’t use first-class functions so much? It’s a systems language, not a functional language for describing algorithms in CS whitepapers. Or use `move` (the article does mention this). There are easy paths in most programming languages, and harder paths. Rust is no exception. The fact…

Yeah, a struct holding four different closures is not a pattern that makes much sense in Rust.

That would look a lot better as a Trait with four methods.

Re: Why asynchronous Rust doesn't work

#13
Async isn't really the problem - the same issue pops up with error handling, with resource management, with anything where you want to pass functions around. The real problem is that Rust's ownership semantics and limited abstractions mean it doesn't really have first-class functions: there are three different function types and the language lacks the power to abstract over them, so you can't generally take an expression and turn it into a function. NLL was actually a major step backwards that has made this worse in the medium term: it papers over a bunch of ownership problems if the code is written inline, but as soon as you try to turn that inlined code into a closure all those ownership problems come back.

IMO the only viable way out is through: Rust needs to get the ability to properly abstract over lifetimes and functions that it currently lacks (HKT is a necessary part of doing this cleanly). A good litmus test would be reimplementing all the language control flow keywords as plain old functions; done right this would obviate NLL.

But yeah that's going to take a while, and in the meantime for 99% of things you should just write OCaml. Everyone thinks they need a non-GC language because "muh performance" but those justifications rarely if ever hold up.

Re: Why asynchronous Rust doesn't work

#14

I'm surprised Rust went with a Scala-inspired async/await considering it wasn't well-liked outside of PLT enthusiasts. JavaScript adopted it as I don't think you could bolt any other type of sugar on top of the event loop in browsers... but Rust shouldn't suffer from such baggage.

Rust was the first language that made it efficient, abstraction without overhead (which took many years of work). It’s just a state machine with an enum holding the state, but of course it means that the memory model is harder to understand than with JavScript.

Re: Why asynchronous Rust doesn't work

#15

I'm surprised Rust went with a Scala-inspired async/await considering it wasn't well-liked outside of PLT enthusiasts. JavaScript adopted it as I don't think you could bolt any other type of sugar on top of the event loop in browsers... but Rust shouldn't suffer from such baggage.

C# and C++ adopted basically the same model.

Re: Why asynchronous Rust doesn't work

#16

I'm surprised Rust went with a Scala-inspired async/await considering it wasn't well-liked outside of PLT enthusiasts. JavaScript adopted it as I don't think you could bolt any other type of sugar on top of the event loop in browsers... but Rust shouldn't suffer from such baggage.

Isn't async/await from F#/C# world, or Scala has a different variant?

Re: Why asynchronous Rust doesn't work

#17
This article is a bit confusing. The concrete issues described all relate to closures, but the author says the real problem is async and they liked Rust before that (when it had the closures they have concrete issues with?).

Re: Why asynchronous Rust doesn't work

#18
For a few months while I was between jobs, I decided to learn Rust. Because async code is supposed to be better than threaded code, I spent all my time trying to write async Rust.

Big mistake! I never accomplished what I set out to accomplish.

Most of my experience is in C#, where the difference between async and threaded code is mostly syntax sugar. (Until you get into the details.) (And async code makes writing UI code much cleaner.)

Trying to write async Rust as a novice is downright hostile. The tradeoff of threads makes async code such that it's only worth it if your Rust process will have highly concurrent load; as opposed to C# where refactoring threaded code to async is housekeeping.

Re: Why asynchronous Rust doesn't work

#19
I could nitpick a few things here (you can use Arc to get around most of the reference-related issues, for example), but I mostly agree with the overall point: some things are just not as ergonomic in Rust, and may never be. I haven't done async stuff in it yet, but I've encountered my own situations where it feels like the language "doesn't really want me to be doing X". And honestly, I think that's okay.

I'm someone who wishes I could use Rust for everything, but I'm coming around to the idea that it isn't really suited to everything. It was designed for the problems faced by low-level programmers, and it continues to be something of a revelation in that area, and it has also really punched above its weight in totally unrelated areas, and that's great. But I don't know if we should expect it to be great at those other areas that are so far outside its core wheelhouse. I think it's good that Rust has an option for async, but comparing its async ergonomics to Go may just be an apples-and-oranges thing.

Re: Why asynchronous Rust doesn't work

#20
post #11

I'm surprised Rust went with a Scala-inspired async/await considering it wasn't well-liked outside of PLT enthusiasts. JavaScript adopted it as I don't think you could bolt any other type of sugar on top of the event loop in browsers... but Rust shouldn't suffer from such baggage.

Do you have a source on people generally disliking async/await? I've become a fan of it in JS.

There's the function coloring issue: https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...

Where your sync functions have X considerations and your async functions have separate Y considerations - BUT, async/await sugar makes these widely different behaviors look nearly identical - so you get "clean" sync code aesthetics on your asynchronous code and are sort of on your own when tracking the behavior of its implication.

Post reply on HN