So I just saw a tweet that shows a piece of code that uses .await
today and I find that that .await
part is not only barely visible, it is also completely indistinguishable from method calls. And this is from a code block that has syntax highlighting.
One of the impressions I have about Rust is that it forces you to explicitly perform operation that are expensive and/or time-consuming (for instance, you must explicitly call .clone()
to clone an object, unlike C++). And in my opinion, that is a good thing.
Regarding await, while I do not consider it expensive, it can potentially be time-consuming (the program have to wait for the future). Having an await
operator that is indistinguishable from field access might encourage programmer to write code that unnecessarily await
s independent futures sequentially:
get_future_1().await + get_future_2().await
while the correct (more performant) code should be:
let (a, b) = get_future_1().join(get_future_2()).await;
a + b
I don't know how can Rust make the "correct (more performant) code" easier to write and read, but I think Rust should make the "wrong code" more explicit by making await
operator more visible. So that whenever I use await
twice or more, the source code will scream to my face that "Hey, you have 2 awaits! Care to join them together?".
Ironically, this also rules out postfix sigil (one that I supported) as it is even more subtle than dot-await Actually, I take that back, because since I find ?
postfix quite noticeable, I think @
postfix must be visible as well