proposal-async-do-expressions icon indicating copy to clipboard operation
proposal-async-do-expressions copied to clipboard

bikeshedding the syntax

Open getify opened this issue 4 years ago • 9 comments

Have you considered options like:

let res1 = do async { .. }   // (edited mistake)

let res2 = do.async { .. }

let res3 = async.do { .. }

If you've explored alternatives (like these or others) and set them aside, it would be helpful to document some of those thoughts here, if for no other reason than to head off some eventual bikeshedding.

getify avatar Jan 29 '21 20:01 getify

async do is already the syntax used in the proposal.

ljharb avatar Jan 29 '21 21:01 ljharb

As @ljharb says, the first is the current proposal. But yes, I've definitely considered a few alternatives, including do async { and async {. I'll write something up discussing these; briefly, I'm currently going with async do because it rhymes with async function.

bakkot avatar Jan 29 '21 21:01 bakkot

It also layers neatly on top of do {, just like async layers neatly on top of function () {.

ljharb avatar Jan 29 '21 21:01 ljharb

So...

const x = async do => { .. }  // I know this is currently a syntax error

const x = async do { .. }

I know that do can't be legally used as a param name, but I'm contemplating how similarly this syntax is going to look to an async arrow with a bare param name. Any other (legal) variation of that param name (like _do, do_, Do, or even some unicode character that looks like "d" or "o") creates a very similar looking syntax, which could make glancing at code harder to distinguish, and also invite typos that "silently" do something different than intended.

I'm not asserting that's a flaw of the current syntax design, just thinking out loud about possible downsides.

getify avatar Jan 29 '21 21:01 getify

I'm hoping that the absence of the arrow token is enough that it's easy to catch the difference, but I agree that's a risk.

bakkot avatar Jan 29 '21 21:01 bakkot

absence of the arrow token

In my experience typing arrows a lot (in FP style coding), I accidentally omit the arrow like 20% of the time. Also, the point of me aligning those two lines up is that ~19 characters have been "scanned" left-to-right before you get the disambiguating signal (the =>).

getify avatar Jan 29 '21 21:01 getify

Surely in that case, a linter, or tests, or running the code would report that do (that you referenced in the body since you took the time to name the parameter) isn't a variable in scope?

ljharb avatar Jan 29 '21 21:01 ljharb

Yes, I'm sure the problem would be caught eventually. I don't run my tools in continual mode where they're checking every keystroke. So I probably wouldn't see it until the next file save or soft-rebuild for checking code running in a browser.

I don't mean to characterize this as a major concern... but I think it's a minor one that should be documented/considered.

getify avatar Jan 29 '21 21:01 getify

The proposed syntax looks great!

do => {} is a syntax error, so i don't see a big problem here... it would be just as much of problem for regular do expressions.

humanchimp avatar Jan 30 '21 03:01 humanchimp