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

6

u/bobindashadows Dec 23 '11

If you introduce "user" at top level scope, you're probably doing it for a reason--most of your functions have the same concept of user, so there's no reason not to make it top level.

The concern isn't that it's silly to add a variable to the top scope, it's that whenever you do add a variable to an upper scope, you have to stop to think "wait - did I use this variable name anywhere else?" If you ignore that possibility, you can break other functions.

-3

u/showellshowell Dec 23 '11 edited Dec 23 '11

It's true that you have to stop to think about whether the variable name exists elsewhere, but it's trivial to find false cognates using your editor. The search is always worthwhile. You either verify that your new name is unique, or you learn more about the code below. For example, if you're introducing "user" at the top, but "user" already exists in other functions, then you might have opportunities for refactoring simplification.