Hacker News new | ask | show | jobs
by goblin89 5039 days ago
A little nitpick, which may be a misconception deserving clarification:

> Our decorators work just like Python method decorators, only we don't need any magic syntax for them because CoffeeScript, like JavaScript, already has this idea that functions can return functions and there's nothing particularly magic about defining a method, it's just an expression that evaluates to a function.

Python also has this idea (called ‘higher-order functions’). The difference is in syntax—function calls require parens in Python, and anonymous functions aren't that well supported. Therefore the need for special syntax construct to make decorator use convenient.

1 comments

You're speaking to the first part of my claim, but not the second, namely that JavaScript and CoffeeScript don't separate the idea of a function and a method, which is what allows you to use first-class functional combinators as decorators.
> JavaScript and CoffeeScript don't separate the idea of a function and a method

Neither does Python, at definition time. All the difference is in the processing performed by the class constructor (`type`) when the class object is created. Before that, it's a bog-standard function.

> which is what allows you to use first-class functional combinators as decorators.

Which is exactly like Python, the original decorators[0][1] predate the syntactic extension by several versions, the original syntax for applying them was:

    def some_method(cls):
        pass
    some_method = classmethod(some_method)
And you could use the exact same syntax to define non-method functions (though not this decorator, of course, as it doesn't make sense for functions)

[0] http://docs.python.org/library/functions.html?highlight=clas...

[1] http://docs.python.org/library/functions.html?highlight=clas...

I only intended to comment on the first part. Decided against cutting the quote mid-sentence. (Which led to me learning something new from masklinn's comment. =))