3 ms·
My roommate (http://thejoshwolfe.blogspot.com/ http://thejoshwolfe.blogspot.com/) pointed out the flaw: The failure of the "var" idea is this code: def ge
by AndyKelley 16y ago
My roommate (http://thejoshwolfe.blogspot.com/ http://thejoshwolfe.blogspot.com/) pointed out the flaw:
The failure of the "var" idea is this code:
def getDataFile():
"returns the string 'data/data.dat'"
var name = "data.dat"
dir = "data"
return os.path.join(dir, name)
now you've clobbered the global function "dir" without realizing.
- Raphael_Amiard 16y agoWell no, if you can't declare any variable without 'var', the ' dir= "data" ' line is very explicitly assignment and not a variable declaration. You can still make the mistake but the piece of code would stand out. The problem in javascript is that "a=12" does create a new variable, even if it's a global, and that many people just go through their code declaring only globals. If you did get a syntax error everytime you did that, you'd soon have the habit of putting var in front of every new variable you declare.
- AndyKelley 16y agoThat's true. All things considered, I think I'd rather have the "var" implementation, crash when using an undeclared variable, and even with the ability to clobber globals if you forget to use "var".