r/programming • u/zumpiez • Dec 22 '11
The Problem with Implicit Scoping in CoffeeScript
http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83
Upvotes
r/programming • u/zumpiez • Dec 22 '11
View all comments
Show parent comment
12
u/munificent Dec 23 '11
Obviously, I'm biased, but I <3 Dart's scoping semantics:
Variable declaration is explicit.
I think state is the source of most of my bugs, so when I'm creating state, especially mutable state, I don't mind having to type a few extra letters to do it.
No top level global object.
This means lexical scope goes all the way to the top. That means that you can statically determine if a name exists or not. That in turn means that:
Will be caught at compile time. It boggles my mind that we use languages that don't do this.
Variables are block scoped.
Since I don't like state, this keeps it as narrowly defined as possible. Along with the previous point, it helps make sure I don't try to use variables when I shouldn't:
Dart will catch this at compile time. JS will just laugh at you while you cry.
Thanks to block scope, closures aren't retarded.
Hoisting and function scope is absolutely monkeys-throwing-feces crazy to me in a language that also has lexical closures. Every time I see an IIFE in JavaScript:
I kind of want to punch myself in the face. (Not to mention JS's weird grammar which forces you to wrap the whole function expression in parens <sigh>.)
For reference, here's Dart:
I understand people were disappointed that Dart wasn't more adventurous, but all of this stuff seems like a Good Thing to me, and an improvement over a lot of other languages people are using right now.