The Problem with Implicit Scoping in CoffeeScript
31–40 of 137 posts
Re: The Problem with Implicit Scoping in CoffeeScript
#32Earlier quoted context omitted.
But he writes coffeescript so unlike you he's a "top programmer". except for times when he writes javascript which probably would be when hes drunk or for whatever reasons his IQ has dropped.
99% of the popular people out there are just above average enough to make useful projects for those lesser experienced. Most truly talented people are not very well known, they're busy hacking on v8, the kernel etc. Tools for average programming just get more of a spotlight. Is Express complex? no, people just use it, is coffeescript complex? no, is boostrap complex? no..
Re: The Problem with Implicit Scoping in CoffeeScript
#33@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.
I think this is a recurring discussion from the dawn of coffeescript. See for example: https://github.com/jashkenas/coffee-script/issues/238 I really don't understand why this isn't being fixed: doesn't global by default break encapsulation? I'm probably missing something, but this is the main reason I haven't tried coffeescript yet.
how_many_times_functions_have_been_called = 0
f1 = ->
how_many_times_functions_have_been_called += 1 # refers to top-level scope
console.log x # undefined
x = 1
console.log x # 1
f2 = ->
f1() # refers to f1 at top-level scope
how_many_times_functions_have_been_called += 1 # refers to lop-level scope
console.log x # undefined
x = 2
console.log x # 2
f1() # you can call f1, it's at top-level scope
f2() # you can call f2, it's at top-level scope
console.log how_many_times_functions_have_been_called # 3, refers to top-level scope
console.log x? # false, x does not exist at top_level scopeRe: The Problem with Implicit Scoping in CoffeeScript
#34Earlier quoted context omitted.
But he writes coffeescript so unlike you he's a "top programmer". except for times when he writes javascript which probably would be when hes drunk or for whatever reasons his IQ has dropped.
99% of the popular people out there are just above average enough to make useful projects for those lesser experienced. Most truly talented people are not very well known, they're busy hacking on v8, the kernel etc. Tools for average programming just get more of a spotlight. Is Express complex? no, people just use it, is coffeescript complex? no, is boostrap complex? no..
Re: The Problem with Implicit Scoping in CoffeeScript
#35Earlier quoted context omitted.
99% of the popular people out there are just above average enough to make useful projects for those lesser experienced. Most truly talented people are not very well known, they're busy hacking on v8, the kernel etc. Tools for average programming just get more of a spotlight. Is Express complex? no, people just use it, is coffeescript complex? no, is boostrap complex? no..
That sounds like a really accurate statistic. So what's your metric for this? Besides the obvious law that low-level code is the only grounds for elite coding, I mean.
Re: The Problem with Implicit Scoping in CoffeeScript
#36FWIW this is how CS works: top_level_variable = null f = -> top_level_variable = "hello" f() console.log top_level_variable # prints hello
foo = ->
bar = "woot!"
console.log bar
This compiles to: var foo;
foo = function() {
var bar;
bar = "woot!";
return console.log(bar);
};
bar is locally scoped to foo(). Now, 2 weeks later and 200 lines earlier, you come along and define: bar = ->
alert "Holy crap cheese is awesome!"
Which compiles to: var bar, foo;
bar = function() {
return alert("Holy crap cheese is awesome!");
};
foo = function() {
bar = "woot!";
return console.log(bar);
};
Now, all of a sudden, the "bar" reference in foo isn't scoped to foo() anymore, it's scoped globally, and once you invoke foo(), it'll replace the function bar with a string, potentially breaking your app. It's an ease-of-maintenance issue.This isn't consistent behavior, though. If you define your top-level bar() function after foo, like so:
foo = ->
bar = "woot!"
console.log bar
bar = ->
alert "Holy crap cheese is awesome!"
Then you get "correct" scoping (and the outer bar is shadowed): var bar, foo;
foo = function() {
var bar;
bar = "woot!";
return console.log(bar);
};
bar = function() {
return alert("Holy crap cheese is awesome!");
};
On one hand, it could be argued that this is a "name things better" problem, but on the other, I have to agree that it'd be nice to be able to explicitly scope things when needed. Given that the behaviors are divergent based on what order the variables appear in, I'd say it's confusing enough that a way to explicitly say "hey, I know what I'm doing, I want to shadow any outer variables and declare local scope here" would be useful.Re: The Problem with Implicit Scoping in CoffeeScript
#37It's open source. Why not fork it and get some like minded coders to change it with you?
Re: The Problem with Implicit Scoping in CoffeeScript
#38Earlier quoted context omitted.
That sounds like a really accurate statistic. So what's your metric for this? Besides the obvious law that low-level code is the only grounds for elite coding, I mean.
Easy, he hand picked a 100 people of the JS community (including him) and then decided that hes the only competent programmer amongst them.
Re: The Problem with Implicit Scoping in CoffeeScript
#39Scheme got this right in 1970. There is no excuse to design a new language this way.
Re: The Problem with Implicit Scoping in CoffeeScript
#40Earlier quoted context omitted.
Easy, he hand picked a 100 people of the JS community (including him) and then decided that hes the only competent programmer amongst them.
umm no haha, I'm certainly amongst the average. Trust me writing parsers is very trivial, I've written many. Thinking you're a good programmer is perhaps the most naive thing you can do