Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the "bind" operator. <- #431

Closed
jashkenas opened this issue Jun 12, 2010 · 14 comments
Closed

Removing the "bind" operator. <- #431

jashkenas opened this issue Jun 12, 2010 · 14 comments

Comments

@jashkenas
Copy link
Owner

There seems to be some talk about the "bind" operator being unnecessary in CoffeeScript. My opinion is that the brevity of function literals makes it a bit superfluous. I certainly haven't used it much. How would y'all feel about getting rid of <- going forward? For the record, the original ticket that introduced it was here:

http://github.com/jashkenas/coffee-script/issues/issue/251

@weepy
Copy link

weepy commented Jun 12, 2010

I've certainly found => useful, not so much <-. Given that bind can be easily added in as function I think it's not really necessary.

@hen-x
Copy link

hen-x commented Jun 12, 2010

I can see it being very useful in the right circumstances, but I don't think it is common enough to be an operator. I'd rather stumble across bind fn, arg1, arg2 in someone else's code than fn <- arg1, arg2, since the first is syntactically consistent with the surrounding code.

The <- syntax is relatively straightforward, but it's not self-documenting, and it's rare enough to be confusing when you come across it.

@weepy
Copy link

weepy commented Jun 12, 2010

You can even extend Function's prototype making it even easier:

fn: (x,y,z) -> x + y + z
bound_fn:  fn.bind @, 1, 2

@jashkenas
Copy link
Owner Author

Thanks for the feedback. The bind operator is now gone on master, along with the couple of places where we made use of it. The documentation will be updated to reflect this change for the next version.

@bnolan
Copy link

bnolan commented Jun 30, 2010

Haha. It's too late now, but I use the <- operator a lot (1 in 10 lines) and find it very helpful and clearer to read than bind syntax (not having to type bind everywhere was a big selling point for coffeescript to me) - but yeah - if it ever is considered for reinclusion I would like that.

@jashkenas
Copy link
Owner Author

bnolan: can you gist an example of the bind-in-1-of-10-lines code? There might be a different way...

@bnolan
Copy link

bnolan commented Jul 1, 2010

From talking on the irc channel, we can fix a lot of it by using the fat arrow when defining methods, but I'm still working on porting our app - then i'll know how many times we actually need <-.

@Mpdreamz
Copy link

I really hope this is re-evaluated
bind's main purpose is to explicitly scope the this context in the function
currying skips the scope context and leaves the context as it is.

Where => helps you to scope to the right context 90% of the time, <- would have helped creating super clean curried functions.

fn2 <- fn(1,2) vs fn2 = fn.curry(1,2) the first definitely wins for me.

@Mpdreamz
Copy link

mental note: 2010 is not 2011.

@JustinMorgan
Copy link

Late, but I'm with bnolan: I use bind all the time, and usually not for currying. I don't really understand why the operator was removed, but I certainly feel its absence. Any plans for bringing <- back, or suggestions for re-implementing it myself?

@akre54
Copy link

akre54 commented Feb 19, 2014

@JustinMorgan Just use Underscore (or your own utils implementation), it shouldn't be a ton of code.

@JustinMorgan
Copy link

It's not too much code, it's just that syntactic sugar for Function.prototype.bind (or even call or apply) would be nice to have (disclaimer: I haven't seen the original <- in action, but intuitively I'd expect x <- y to be equivalent to x.bind y). I'm not really too worried about backwards compatibility.

I often find myself setting context at call time, and args = do [].slice <- arguments feels more fluent and intuitive than args = [].slice.call arguments.

@akre54
Copy link

akre54 commented Feb 19, 2014

args = do [].slice <- arguments feels more fluent and intuitive than args = [].slice.call arguments

😕 really? Do you, man :P

I think you'll find CoffeeScript aint gonna add this particular sugar back for the reasons listed before

@JustinMorgan
Copy link

Fair enough. No biggie.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants