Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap the roles of in and of #702

Closed
satyr opened this issue Sep 22, 2010 · 10 comments
Closed

Swap the roles of in and of #702

satyr opened this issue Sep 22, 2010 · 10 comments

Comments

@satyr
Copy link
Collaborator

satyr commented Sep 22, 2010

I find it pretty confusing that of compiles to in and in arraywise operations.
It'd be easier for beginners if we kept the meaning of in from JS and then introduced of for a cool addition.

According to Jeremy it's all about readability, but for me neither reads much better than another:

  • Current
    • for key of object
      • for key, value of object
    • for item in array
      • for item, index in array
  • Proposed
    • for key in object
      • for key, value in object
    • for item of array
      • for item, index of array

Do you feel one much more readable than another?

@jacquescrocker
Copy link

i do think in should be used for array. of seems fine to me for hashes

-1

@michaelficarra
Copy link
Collaborator

I've had this gripe since I first came across coffeescript, but I thought I was alone and/or nitpicking. +1 for consistency with JS. I even think the proposed syntax reads slightly better.

edit: I'd like to note that, since posting this comment almost a year ago, my opinion on this matter has reversed, as can be seen in more recent issues proposing similar changes.

@timmfin
Copy link

timmfin commented Sep 22, 2010

-1

Most of the dynamic languages I'm used to (ruby, python, groovy, etc) use a for ... in for arrays. I think that js is the exception here, and of and in should stay the same.

@satyr
Copy link
Collaborator Author

satyr commented Sep 22, 2010

use a for ... in for arrays

Also for hashes.

Ruby:

for k, v in {a:1, b:2}; p [k, v] end

Python:

for k, v in {'a':1, 'b':2}.items(): print k, v

Groovy:

for(e in [a:1, b:2]) println([e.key, e.value])

It's just that hash (object) in JS is more fundamental data structure than array.

@weepy
Copy link

weepy commented Sep 22, 2010

I think its best to follow javascripts convention where possible. That is certaintly what I am doing with Kaffeine (though this is because it implements progressive enhancement of Javascript syntax, it has to). But I think CS should do the same.

@stephank
Copy link

I've personally never used in in JS for object attribute iteration, but have used it for iterating arrays. So even coming from JS, the current syntax seems natural to me.

That, and the consistency with other languages, makes me say -1.

@StanAngeloff
Copy link
Contributor

of object (belongs to) and in array (in list) make sense. -1

@hen-x
Copy link

hen-x commented Sep 23, 2010

-1 from me. As array items in JS are implemented as normal object properties, the fine distinction between them is always going to be a potential point of confusion, so it would be hard to devise an iteration syntax that is completely unambiguous. However, since the semantic difference is a matter of object properties versus array contents, I think of and in make fine sense as they are.

@jashkenas
Copy link
Owner

Sounds like nearly unanimous consensus, then. To reiterate, the original reason for the different terminology is just regular English: You can say "item in list", and "property of object" -- but "item of list" and "property in object" both sound strange-ish.

Closing the ticket.

@satyr
Copy link
Collaborator Author

satyr commented Jul 10, 2011

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants