| > it's drawing back from the OO/Func movement of the JS community back into procedural and statements-based something fierce This statement is completely incorrect, the truth is actually the exact opposite. First I would note there is no such thing as a statement in Coffeescript. Everything is an expression ... this may seem like a minor point to some, but it's actually quite a powerful difference. As with a lot of the things CS adds, It's hard to appreciate the boost in expressiveness until you start writing a lot of code with it. If you want to talk about functional programming, expressions rather than statments count as 1 whole point out of 9 for PG's "list of things that are awesome about lisp". Another important aspect of functional programming is lambdas, JavaScript does not have "real lambdas" because of the lack of implicit returns and the aforementioned quality. By adding them, CS get's you much closer to real lambdas. This combined with the light syntax for functions encourages one to program in a much more functional style. These qualities enable say, quick and easy decorators: logged = ( f , named_f ) ->
if named_f? then [ f, name ] = [ named_f, f ] else name = "function"
# decorated function, to be returned
( args... ) ->
console.log "#{name} (#{f.length}) with #{args.length} args."
f.apply @, args
# random function, note our decorator preserces "this"
foo = logged ( x ) ->
console.log( @[x] + "" )
# random function that calls other function, our logging lets us trace the calls
# this one provides a name
bazz = logged "bazz", ( x ) ->
foo.call @, x
# test
bar = fizz: "buzz"
bazz.call bar, "fizz"
Note also how splats simplifies this operation. Destructuring and the existential operator makes the logic in the decorator function a little cleaner. String interpolation makes the logging easier.Additionally the use of implicitness really makes it shine and fit together well, rather than being mere eye-candy. There's no wrapping in parens to decorate, making it harder to mess up, easier to modify, and easier to parse visually and perhaps programatically. I think a lot of people are deceived when it comes to CoffeeScript, they see a lot of little things which seem nice...but individually they seem pointless or minor. They are deceived on two parts: a lot of these "little things" are actually quite powerful on their own, and additionally they mesh in a way that is greater than the sum of the parts. All these little nice things can add a powerful boost to expressiveness and once you spend some time with them it really changes how you think and write code. That's another thing I would note is that CoffeeScript is for people who want more expressiveness/find these things more expressive. If you are looking for something else, or think in a way that has an impedance mismatch with the CoffeeScript philosophy, obviously you should look elsewhere. (If anyone's curious, this decorator makes it so every time a decorated function is called, it logs the function's name if provided, the number of defined arguments it takes, and how many
it was actually passed.) I would also note that scopes function the same in CS as they do in JS, the only difference is that in CS you cannot shadow variables from an enclosing scope, and there are no implicit globals. In terms of OO, CS adds syntactic sugar for perhaps the most common inheritance pattern in JS. I would argue both of those are good things, though I respect other people might think otherwise. |