The Problem with Implicit Scoping in CoffeeScript
lucumr.pocoo.org
The Problem with Implicit Scoping in CoffeeScript
1–10 of 137 posts
Re: The Problem with Implicit Scoping in CoffeeScript
#2Re: The Problem with Implicit Scoping in CoffeeScript
#3Once you understand the reach of CoffeeScript's top-level variables, it is easy to write bug-free code. Since you know that top-level variables have wide scope, you simply need to be judicious about putting variables at top-level scope. If a variable is not needed at top level scope, don't put it there.
Re: The Problem with Implicit Scoping in CoffeeScript
#4CoffeeScript's approach toward top-level variables is quite elegant and simple. When you declare a variable at top-level scope, it is equally available to all code within that file for both reading and writing, with no strange "nonlocal" or ":=" syntax to complicate manners. Once you understand the reach of CoffeeScript's top-level variables, it is easy to write bug-free code. Since you know that top-level variables…
Re: The Problem with Implicit Scoping in CoffeeScript
#5Scheme got this right in 1970. There is no excuse to design a new language this way.
Re: The Problem with Implicit Scoping in CoffeeScript
#6How arrogant! You'd think he'd step back for a second and consider the suggestion, but it sounds like he's on autopilot.
Re: The Problem with Implicit Scoping in CoffeeScript
#7CoffeeScript's approach toward top-level variables is quite elegant and simple. When you declare a variable at top-level scope, it is equally available to all code within that file for both reading and writing, with no strange "nonlocal" or ":=" syntax to complicate manners. Once you understand the reach of CoffeeScript's top-level variables, it is easy to write bug-free code. Since you know that top-level variables…
Way to miss the issue. I was not suggesting ":=" for global variables at all. I was suggesting ":=" as a replacement for the nonlocal keyword that Python 3 has to solve the issue I was demonstrating.
Obviously, plenty of folks managed to write bug-free code in Python before "nonlocal" was invented. I'm not saying it's a bad idea, but you can avoid bugs without it.
Re: The Problem with Implicit Scoping in CoffeeScript
#8Earlier quoted context omitted.
Way to miss the issue. I was not suggesting ":=" for global variables at all. I was suggesting ":=" as a replacement for the nonlocal keyword that Python 3 has to solve the issue I was demonstrating.
Nope, I get it, you were suggesting ":=" as a replacement for the "nonlocal" keyword in Python. I'm not sure how my comments demonstrate any lack of reading comprehension. All I said about ":=" and "nonlocal" is that they are overly complicated once you accept that top-level variables can have wide scope. Obviously, plenty of folks managed to write bug-free code in Python before "nonlocal" was invented. I'm not sayin…
Python has the inverse behavior of CoffeeScript. So that was never an issue.
Re: The Problem with Implicit Scoping in CoffeeScript
#9Here is an example of what I'm talking about:
if isAir cx, cy, cz + 1 then addPlane('near', block)
Should be:
if isAir cx, cy, cz + 1 then addPlane 'near', block
Personally, I use them everywhere because I like having the stronger visual clue that this is a method I'm calling. I think making them optional in CS was a bad idea.
if isAir(cx, cy, cz + 1) then addPlane('near', block)
imho, so much more readable.
Re: The Problem with Implicit Scoping in CoffeeScript
#10@mitsuhiko Not gonna happen ;) Forbidding shadowing altogether is a huge win, and a huge conceptual simplification. How arrogant! You'd think he'd step back for a second and consider the suggestion, but it sounds like he's on autopilot.