Re:The Problem with Implicit Scoping in CoffeeScript
by showell30 on Wednesday December 21, 2011 @10:41PM
(#3380263)
You are correct that variable scoping goes all the way to the top, but nobody is forcing you to create top-level variables with overloaded names like "log". Seriously, if you have a file that uses log files and logarithms, just take some care to distinguish the concepts. Use "log_file" for log files; use "logarithm" or "Math.log" for inverse exponentation.
[ Parent
| on HN ]
Re:The Problem with Implicit Scoping in CoffeeScript
by xnxn on Wednesday December 21, 2011 @11:15PM
(#3380354)
> Use "log_file" for log files; use "logarithm" or "Math.log" for inverse exponentation.
Just clarifying; are you actually suggesting this, or was that sarcasm?
Re:The Problem with Implicit Scoping in CoffeeScript
by showell30 on Thursday December 22, 2011 @12:22AM
(#3380510)
It's a serious suggestion. Instead of introducing four top-level variables (log, sin, cos, and tan), just introduce one (Math) that wouldn't possibly conflict with a local.
Re:The Problem with Implicit Scoping in CoffeeScript
by the_mitsuhiko on Thursday December 22, 2011 @06:02AM
(#3381138)
The CoffeeScript sourcecode itself does not advocate it. It uses functions named like 'last', 'starts', 'ends', 'extend' etc.
Re:The Problem with Implicit Scoping in CoffeeScript
by showell30 on Thursday December 22, 2011 @08:45AM
(#3381476)
You are correct about "last", "start's, etc., but there are also good examples in the CS sourcecode of easily avoiding naming conflicts with a sensible naming convention:
browser.coffee:CoffeeScript = require './coffee-script'
coffee-script.coffee:{Lexer,RESERVED} = require './lexer'
coffee-script.coffee: {Module} = require 'module'
command.coffee:{EventEmitter} = require 'events'
grammar.coffee:{Parser} = require 'jison'
lexer.coffee:{Rewriter, INVERSES} = require './rewriter'
nodes.coffee:{Scope} = require './scope'
nodes.coffee:{RESERVED} = require './lexer'
repl.coffee:{Script} = require 'vm'