{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4907","repository_url":"https://api.github.com/repos/jashkenas/coffeescript","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4907/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4907/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4907/events","html_url":"https://github.com/jashkenas/coffeescript/issues/4907","id":298149510,"number":4907,"title":"CS2 Discussion: Features: decorators","user":{"login":"coffeescriptbot","id":36576729,"avatar_url":"https://avatars1.githubusercontent.com/u/36576729?v=4","gravatar_id":"","url":"https://api.github.com/users/coffeescriptbot","html_url":"https://github.com/coffeescriptbot","followers_url":"https://api.github.com/users/coffeescriptbot/followers","following_url":"https://api.github.com/users/coffeescriptbot/following{/other_user}","gists_url":"https://api.github.com/users/coffeescriptbot/gists{/gist_id}","starred_url":"https://api.github.com/users/coffeescriptbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coffeescriptbot/subscriptions","organizations_url":"https://api.github.com/users/coffeescriptbot/orgs","repos_url":"https://api.github.com/users/coffeescriptbot/repos","events_url":"https://api.github.com/users/coffeescriptbot/events{/privacy}","received_events_url":"https://api.github.com/users/coffeescriptbot/received_events","type":"User","site_admin":false},"labels":[{"id":841194363,"url":"https://api.github.com/repos/jashkenas/coffeescript/labels/new%20feature","name":"new feature","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-19T03:00:21Z","updated_at":"2018-02-19T03:00:23Z","closed_at":null,"author_association":"COLLABORATOR","body":"---\n\nMigrated from https://github.com/coffeescript6/discuss/issues/9\nOriginally created by @rattrayalex on *Sat, 23 Jul 2016 02:51:33 GMT*\n\n---\nDecorators are an increasingly popular feature of ES6, particularly with React development. \n\nHowever, they use `@atSyntax`, which clashes with coffeescript's `this.` shorthand. \n\nWe could: \n1. Come up with an alternative syntax for decorators\n2. Come up with a new syntax for `this.` shorthand\n3. Keep both as they are and just work hard to parse them\n4. Get rid of `this.` shorthand\n5. Don't add decorators\n6. Any other ideas?\n\nThoughts?\n"},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/366577862","html_url":"https://github.com/jashkenas/coffeescript/issues/4907#issuecomment-366577862","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4907","id":366577862,"user":{"login":"coffeescriptbot","id":36576729,"avatar_url":"https://avatars1.githubusercontent.com/u/36576729?v=4","gravatar_id":"","url":"https://api.github.com/users/coffeescriptbot","html_url":"https://github.com/coffeescriptbot","followers_url":"https://api.github.com/users/coffeescriptbot/followers","following_url":"https://api.github.com/users/coffeescriptbot/following{/other_user}","gists_url":"https://api.github.com/users/coffeescriptbot/gists{/gist_id}","starred_url":"https://api.github.com/users/coffeescriptbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coffeescriptbot/subscriptions","organizations_url":"https://api.github.com/users/coffeescriptbot/orgs","repos_url":"https://api.github.com/users/coffeescriptbot/repos","events_url":"https://api.github.com/users/coffeescriptbot/events{/privacy}","received_events_url":"https://api.github.com/users/coffeescriptbot/received_events","type":"User","site_admin":false},"created_at":"2018-02-19T03:00:22Z","updated_at":"2018-02-19T03:00:22Z","author_association":"COLLABORATOR","body":"---\n\nMigrated from https://github.com/coffeescript6/discuss/issues/9#issuecomment-235975114\nOriginally created by @carlsmith on *Thu, 28 Jul 2016 18:00:50 GMT*\n\n---\n`-1` on this. CoffeeScript already has decorators. ES3 already has them too. Every language with first-class functions supports decorators. What ES6 is adding is just syntactic sugar for passing a function to a decorator. CoffeeScript already has syntactic sugar for doing this, and it literally couldn't be improved on. You just put any expression (typically a name) that evaluates to a decorator in front of the function expression you want to decorate. If you have a decorator named `memo`, you can just put `memo` in front of anything you want to decorate.\r\n\r\n``` coffee\r\n# regular square function\r\nsquare = (x) -> x * x\r\n# memo decorated square function\r\nsquare = memo (x) -> x * x\r\n```\r\n\r\nWe don't need ES6 sugar in CoffeeScript. That's the whole point of CoffeeScript.\r\n\r\nDecorators are an awesome feature, but every language already has them. It's just that some languages make applying them awkward. Python without special syntax:\r\n\r\n``` python\r\ndef square(x): return x * x\r\nsquare = memo(square)\r\n```\r\n\r\nPython with special syntax:\r\n\r\n``` python\r\n@memo\r\ndef square(x): return x * x\r\n```\r\n\r\nThere's absolutely no need for special syntax in CoffeeScript. If we had to use parens for invocations, it'd be different:\r\n\r\n``` coffee\r\nsquare = memo((x) -> x * x)\r\n```\r\n\r\nFrom experience, I can say confidently that you never need those parens in practice. You can always use the name of a decorator as if it's a prefix operator.\r\n\r\nThings are less pretty if you use functions that return decorators, but it still works well enough. You just wrap the decorator expression in parens:\r\n\r\n``` coffee\r\nsquare = (memo 10) (x) -> x * x\r\n```\r\n\r\nThat could be a little bit prettier with special syntax, for example:\r\n\r\n``` coffee\r\n@memo 10\r\nsquare = (x) -> x * x\r\n```\r\n\r\nBut, it's a pretty big change to add minor convenience to a rare construct, and the new syntax would be awful when using functions as args:\r\n\r\n``` coffee\r\nemployees.forEach(\r\n    @memo 10\r\n    (each) -> console.log each\r\n)\r\n```\r\n\r\nThat's a mess, especially when we already have:\r\n\r\n``` coffee\r\nemployees.forEach (memo 10) (each) -> console.log each\r\n```\r\n\r\nDecorators never nest any deeper than that. You always either use a decorator, or call a function that returns a decorator (so you can parameterise the decorator). They are the only two forms decoration takes.\r\n"}}
{"actor":{"display_login":"coffeescriptbot"}}