Re:Dropbox dives into CoffeeScript
by jarek-foksa on Friday September 14, 2012 @03:45AM
(#4520611)
I always felt that function hoisting is harming code readability. I prefer reading the code from top to bottom, I don't want to stuble upon functions that were not declared before.
If I recall correctly the main reason why this feature is not supported by CoffeeScript is because of some awkward IE bug though.
The main reason is what you say -- it harms readability. Much better to have functions behave like any other value, like any other variable -- and only be usable after they've been created.
I agree, although I also see some usefulness:
If your inner function names are sufficiently descriptive, you can write the high-level behaviour of the outer function at the top, first to be read, to get a quick overview of what it does. Then declare the inner functions below that (this also requires that the inner functions must not have surprising side-effects).
I've never seen or tried out code like that in practice, but it seems like it could work.
(Genuine question, not an snarky comment)
Edit: Huh! I thought you meant "variable hoisting", which is the most evil language feature that's ever bitten me!
This is an introduction to "function hoisting": http://elegantcode.com/2011/03/24/basic-javascript-part-12-f... - Very very interesting.