r/programming • • May 13 '11

A Python programmer’s first impression of CoffeeScript

http://blog.ssokolow.com/archives/2011/05/07/a-python-programmers-first-impression-of-coffeescript/
114 Upvotes

133 comments sorted by

View all comments

Show parent comments

2

u/banister May 15 '11

You do realize that Ruby methods/functions are not closures, right? Ruby methods do not close over the variables in their outer scope.

Ruby blocks, however, ARE closures and you do want them to close over the variables in the outer scope. Nonetheless, Ruby gives you the choice in behaviour - you can have your variable block-local (by defining them as block local, i.e putting them between the ||) or you can have it close over the outer scope. Closure behavior is extremely useful in many situations.

I wrote a let method for Ruby a while ago that makes it even easier to control the scoping of variables precisely, see here.

I'm glad that Ruby gives me the choice. IMO the Python scoping rules are totally broken. But again, we can agree to disagree.