I strongly dislike postfix keyword syntax. Here’s why:
Readability: We can only say we “await something”
When we wait for a future, we say we await future
, not future.await
.
We say “future awaits” (future.await
) when we mean a future is approaching, which somewhat makes sense in some other context but does not describe what we are doing.
What postfix await
is trying to solve is but one niche use case
The only reason (that I’ve seen so far) to have a postfix syntax is method chaining and error handling:
let _ = future.await?.something_else();
But this is but one niche use case, is it really worth sacrificing readability and familiarity of classic prefix await
syntax?
I strongly dislike postfix keywords (in general) as well
I mean, just look at this abomination:
codition.if { foo }.then { bar }
Alternate proposal 1: Postfix Symbol
I only dislike postfix keywords, but I am OK with postfix symbol, especially since I love using postfix ?
syntax.
The above code snippet can be rewritten into this:
let _ = future@?.something_else();
Not only is this syntax way shorter than postfix await
, it is also consistent with the rest of the language, especially postfix ?
syntax.
Alternate proposal 2: Smart Pipeline
Dot syntax was never designed for method chaining, it just so happen that it is possible and JavaScript popularized it.
But pipeline operator was born for that purpose.
With smart pipeline, the above code snippet can be rewritten into this:
let _ = future |> await _ |> _? |> .something_else();
Or this:
let _ = future |> (await _)? |> .something_else();
Or this:
let _ = future |> await? |> .something_else();