jhusain / asyncgenerator

Asynchronous Generators for ES7
391 stars 22 forks source link

"on" and "in" might be too similar when skimming code. #3

Closed benlesh closed 10 years ago

benlesh commented 10 years ago

This might be a small thing, but I worry that many developers might run into hard to suss out issues when debugging code using the syntax as proposed. I was in a hurry the first time I looked at this document and I thought it was a for ..in block. But that puzzled me because I couldn't figure out how the parser would know to treat the async iterator differently. It took me a few reads to realize it was for ..on. Now I'm a little jet-lagged, so maybe that isn't helping, but wouldn't a for ..await be more descriptive and easier to read?

for(var foo in foos()) {
  /* do things */
}

for(var foo on foos()) {
  /* do things */
}

for(var foo await foos()) {
  /* do things */
}
benlesh commented 10 years ago

To be clear, I'm not specifically saying "await" is the best idea, or even a good idea. I'm simply saying that on and in might look too similar when skimming code.

benlesh commented 10 years ago

Once I'm sure this is seen, I'm closing this myself, because it's probably not a big deal, but I wanted to at least express the concern. in, on and of all look very similar when skimming code, they each have distinct typographic "coastlines", but do not differ at all in word size, and barely differ in letter content across in -> on -> of despite being only two letters each. on is the joining factor there between in and of

jayphelps commented 10 years ago

You're not alone. I've thought the same thing. in, of, on..

I'm the kind of dev who would rather be verbose if it makes it easier to understand/read.

I'd need to check to grammar, but I believe you should still be able to do:

for (let foo of await foos()) {}

Or even:

for (let [key, foo] in await foos()) {}

Maybe C# is throwing me off though. When I have some time I'll check the grammar. (of course someone may chime in before)

jhusain commented 10 years ago

I don't disagree necessarily with these concerns. However this issue was really settled with the addition of "for...of" in ES6. ES6 sets the principle that we shouldn't go too far to differentiate these with very different looking concepts. The "for...on" loops follows that principle.