by michaelty on 12/22/11, 1:44 AM with 134 comments
by mhansen on 12/22/11, 1:25 PM
"""
Sorry, folks, but I'm afraid I disagree completely with this line of reasoning -- let me explain why:
Making assignment and declaration two different "things" is a huge mistake. It leads to the unexpected global problem in JavaScript, makes your code more verbose, is a huge source of confusion for beginners who don't understand well what the difference is, and is completely unnecessary in a language. As an existence proof, Ruby gets along just fine without it.
However, if you're not used to having a language without declarations, it seems scary, for the reasons outlined above: "what if someone uses my variable at the top of the file?". In reality, it's not a problem. Only the local variables in the current file can possibly be in scope, and well-factored code has very few variables in the top-level scope -- and they're all things like namespaces and class names, nothing that risks a clash.
And if they do clash, shadowing the variable is the wrong answer. It completely prevents you from making use of the original value for the remainder of the current scope. Shadowing doesn't fit well in languages with closures-by-default ... if you've closed over that variable, then you should always be able to refer to it.
The real solution to this is to keep your top-level scopes clean, and be aware of what's in your lexical scope. If you're creating a variable that's actually a different thing, you should give it a different name.
Closing as a wontfix, but this conversation is good to have on the record.
"""
by gcv on 12/22/11, 4:40 AM
by rayiner on 12/22/11, 2:12 AM
by limeblack on 12/22/11, 4:20 AM
Although the following examples could become unambiguous with parenthesis, these examples demonstrates how a trivially overlooked ending delimiter further complicated the language. Not only is the intent of the CoffeScript code unclear in the examples below but the slight variation in the CoffeScript, produces radically different output. The CoffeeScript differences are so small it would be easy for someone to add accidentally while editing. Anonymous function passing and function calling in Javascript require no additional wrappers or edits, while in CoffeeScript you must add special case clarity.
http://img542.imageshack.us/img542/7379/coffeescripttojavasc...
by oinksoft on 12/22/11, 2:35 AM
How arrogant! You'd think he'd step back for a second and consider the suggestion, but it sounds like he's on autopilot.
by stoodder on 12/22/11, 3:56 AM
by tjholowaychuk on 12/22/11, 3:24 AM
by leafo on 12/22/11, 3:03 AM
I didn't want to change the default semantics, but I wanted to have a way for the programmer to be safe if they wanted to, so I created the `using` keyword for function declarations.
You explicitly declare what you intend to overwrite in the lexical scope, including overwriting nothing at all with `using nil`.
by buddydvd on 12/22/11, 7:15 AM
http://www.rubyist.net/~matz/slides/rc2003/mgp00010.html
Source: https://github.com/jashkenas/coffee-script/issues/712#issuec...
by gerggerg on 12/22/11, 4:08 AM
It's open source. Why not fork it and get some like minded coders to change it with you?
by danmaz74 on 12/22/11, 12:42 PM
If you need global variables, it's sensible to just adopt a simple naming convention, like prepending g_ (or whatever pleases you) to all your variables. I already did that with plain JS and it's well worth the "effort".
by latchkey on 12/22/11, 2:41 AM
Here is an example of what I'm talking about:
if isAir cx, cy, cz + 1 then addPlane('near', block)
Should be:
if isAir cx, cy, cz + 1 then addPlane 'near', block
Personally, I use them everywhere because I like having the stronger visual clue that this is a method I'm calling. I think making them optional in CS was a bad idea.
if isAir(cx, cy, cz + 1) then addPlane('near', block)
imho, so much more readable.
by showell30 on 12/22/11, 2:20 AM
Once you understand the reach of CoffeeScript's top-level variables, it is easy to write bug-free code. Since you know that top-level variables have wide scope, you simply need to be judicious about putting variables at top-level scope. If a variable is not needed at top level scope, don't put it there.
by perfunctory on 12/22/11, 9:22 AM
by shaunxcode on 12/22/11, 10:56 PM
((a = 5, b = 6, log = x -> console.log x) -> log a + b)()
by cvshepherd on 12/22/11, 2:25 PM
I disagree. The simple solution to this is to write tests.
by showell30 on 12/22/11, 3:13 AM
top_level_variable = null
f = ->
top_level_variable = "hello"
f()
console.log top_level_variable # prints hello