r/programming • • Dec 22 '11

The Problem with Implicit Scoping in CoffeeScript

http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83 Upvotes

116 comments sorted by

View all comments

Show parent comment

4

u/munificent Dec 23 '11

When I write x = 1, I'm saying that the value of x right now is 1, and everything in the current scope and below this point can access that value.

OK, that's an interesting way to look at it. I still like explicit variable declarations because I like to know how far up I have to read to understand the extent of a variable. Once I see a var I know I don't have to consider anymore surrounding scopes.

Patterns that do optimize for cut-and-paste programming tend to favor local isolation -- Instead, we're aiming for the holistic readability of the code.

That makes sense. I generally aim for trying to minimize the amount of context a person needs to have in order to understand code so I lean towards composability and isolation but your angle is valid too.

as you read, each variable is local to the scope where it was first introduced.

True, but (for better or worse!) I rarely find myself reading an entire source file from top to bottom.