Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created October 25, 2011 14:54
Show Gist options
  • Save rentalcustard/1313015 to your computer and use it in GitHub Desktop.
Save rentalcustard/1313015 to your computer and use it in GitHub Desktop.
Why I don't like coffeescript
#Given a function that accepts a callback...
someFunc = (callback) ->
#do stuff
callback(data) if callback
#when calling it...
someFunc (data) ->
#blah
#it's not clear until you see the '->' symbol that (data)
# is the list of arguments to the anonymous callback function
# rather than an argument to the someFunc() call. And even
# after you see it, there's only a single character difference
# between calling someFunc with a function and declaring a
# function called someFunc which accepts a function.
@mikekelly
Copy link

You've used parens on:

callback(data)

why not

someFunc( (data) -> .. )

Do you often write functions that take a single callback as the only argument? This doesn't read so bad:

someFunc opts, (data) -> ..

There's also the confusion created by picking nondescript names for stuff, which shouldn't happen in practice.

@rentalcustard
Copy link
Author

I'm trying to reduce a general difficulty I have with reading (other people's) Coffeescript to its simplest form. I agree that putting parens around the call makes it (slightly) easier to read.

I'm looking at code that is callback heavy (probably too callback-heavy, but that's another story...) and I still find the 'arguments before function symbol' syntax highly confusing when nested inside a call to another function:

```
http.createServer( (req, res) ->
  key = url.parse(req.url, true).query.id
  database.open((err, connected) ->
    retrieveUri(key, connected, (uri, connected) -> 
    #etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment