Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Why is function binding not the default?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brian Nesbitt  
View profile  
 More options Jan 23 2012, 10:55 am
From: Brian Nesbitt <br...@nesbot.com>
Date: Mon, 23 Jan 2012 07:55:36 -0800 (PST)
Local: Mon, Jan 23 2012 10:55 am
Subject: Why is function binding not the default?

Hello.

I have just started to pickup coffeescript in the past few days.  Thought I
would share my first post about the -> vs =>
Seems to be a common gotcha when first starting out.

http://nesbot.com/2012/1/20/CoffeeScript-why-is-function-binding-not-...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile  
 More options Jan 23 2012, 2:13 pm
From: Mark Hahn <m...@hahnca.com>
Date: Mon, 23 Jan 2012 11:13:03 -0800
Local: Mon, Jan 23 2012 2:13 pm
Subject: Re: [coffeescript] Why is function binding not the default?

I rarely need the fat arrow.  Maybe you are using a coding style that does
need it?

If you nest several fat arrows the javascript gets really messy and hard to
read.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jarek Foksa  
View profile  
 More options Jan 24 2012, 12:35 am
From: Jarek Foksa <ja...@kiwi-themes.com>
Date: Tue, 24 Jan 2012 06:35:03 +0100
Local: Tues, Jan 24 2012 12:35 am
Subject: Re: [coffeescript] Why is function binding not the default?

On Mon, Jan 23, 2012 at 8:13 PM, Mark Hahn <m...@hahnca.com> wrote:
> I rarely need the fat arrow.  Maybe you are using a coding style that does
> need it?

> If you nest several fat arrows the javascript gets really messy and hard to
> read.

I have heard this argument several times, but I still dont get it how you could
avoid fat arrows. Do you know of any examples of such coding style?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile  
 More options Jan 24 2012, 2:23 am
From: Mark Hahn <m...@hahnca.com>
Date: Mon, 23 Jan 2012 23:23:51 -0800
Local: Tues, Jan 24 2012 2:23 am
Subject: Re: [coffeescript] Why is function binding not the default?

>   Do you know of any examples of such coding style?

I tend to use closures heavily and rarely use @, except in jQuery
callbacks.  I don't use classes as I find I can use closures anywhere I am
tempted to use a class.  Without classes and OOPS, @ isn't used much.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jarek Foksa  
View profile  
 More options Jan 24 2012, 4:12 am
From: Jarek Foksa <ja...@kiwi-themes.com>
Date: Tue, 24 Jan 2012 10:12:19 +0100
Local: Tues, Jan 24 2012 4:12 am
Subject: Re: [coffeescript] Why is function binding not the default?

> I tend to use closures heavily and rarely use @, except in jQuery callbacks.
>  I don't use classes as I find I can use closures anywhere I am tempted to
> use a class.  Without classes and OOPS, @ isn't used much.

But closures provide only a way to encapsulate the code, by
avoiding class or prototype objects you are losing the ability to reuse
code, which is imho *huge* disadvantage compared to the little discomfort
associated with the usage of fat arrows.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 24 2012, 6:26 am
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 24 Jan 2012 03:26:34 -0800 (PST)
Local: Tues, Jan 24 2012 6:26 am
Subject: Re: [coffeescript] Why is function binding not the default?

Can you explain how classes and prototypes are essential to code reuse?  You don't need them for encapsulation, nor do you need them for namespacing.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Brody  
View profile  
 More options Jan 24 2012, 7:22 am
From: Chris Brody <chris.br...@gmail.com>
Date: Tue, 24 Jan 2012 13:22:08 +0100
Local: Tues, Jan 24 2012 7:22 am
Subject: Re: [coffeescript] Why is function binding not the default?
IMHO which features from classes, prototypes, functional programming,
etc. should be used depends on the design, architecture, and
requirements; and JavaScript and CoffeeScript are quite flexible.
JQuery is providing a lot of functionality and is using its own
"object-oriented programming" (OOP) under the hood, so in many cases
very basic if any "OOP" will be required in an application itself. I
read somewhere about making functions act like objects in LISP,
unfortunately I lost the link but this is entirely possible and
relatively easy in JavaScript and CoffeeScript.

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Hartnup  
View profile  
 More options Jan 24 2012, 7:30 am
From: John Hartnup <john.hart...@gmail.com>
Date: Tue, 24 Jan 2012 12:30:06 +0000
Local: Tues, Jan 24 2012 7:30 am
Subject: Re: [coffeescript] Why is function binding not the default?

On 24 January 2012 12:22, Chris Brody <chris.br...@gmail.com> wrote:

> I read somewhere about making functions act like objects in LISP,

This is a major step towards Functional Programming enlightenment.

If function A returns a function B which is a closure around A's variables,
then A is an "object" and B is a "method".

If function C returns function A, which has its own set of variables, then
C is a "constructor" for A.

It's a tangent, but it shows how you can apply your OO habits to FP.

If you have an hour to spare, this presentation is very informative (and
not as Java-centric as the title suggests).
http://www.infoq.com/presentations/It-Is-Possible-to-Do-OOP-in-Java

--
"There is no way to peace; peace is the way"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jarek Foksa  
View profile  
 More options Jan 24 2012, 7:46 am
From: Jarek Foksa <ja...@kiwi-themes.com>
Date: Tue, 24 Jan 2012 13:46:48 +0100
Local: Tues, Jan 24 2012 7:46 am
Subject: Re: [coffeescript] Why is function binding not the default?

> Can you explain how classes and prototypes are essential to code reuse?

I can't think of any better way for code reuse. You could probably use
some factory methods, call/apply or mixins, but they are not as flexible
as prototypes.

Let's say that I wanted to implement edit button. With prototypes I would
do something like this (I'm using __proto__ because it's easier to read):

widget =
  __proto__: Object.prototype
  init: -> ...
  tooltipText: ''
  showTooltip: -> ...
  hideTooltip: -> ...
  enable: -> ...
  disable: -> ...

button =
  __proto__: widget
  init: -> ...
  label: ''
  width: 50
  height: 50

editButton =
  __proto__: button
  init: -> ...
  label: 'Edit'
  tooltipText: 'Click to edit'

Now I can easily reuse the code I have written. E.g. if later I wanted
to create another edit button that is two times bigger:

bigEditButton =
  __proto__: editButton
  width: 200
  height: 80

If I wanted to create toggle button:

toggleButton =
  __proto__: button
  toggleOn: -> ...
  toggleOff: -> ...

If I wanted to create popup menu:

popupMenu =
  __proto__: widget
  items: ...
  expand: -> ...
  collapse: -> ...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 24 2012, 9:39 am
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 24 Jan 2012 06:39:24 -0800 (PST)
Local: Tues, Jan 24 2012 9:39 am
Subject: Re: [coffeescript] Why is function binding not the default?

Thanks for the explanation.  You're describing inheritance, and I agree that classes/prototypes make that pattern pretty flexible and easy to code.  Now I'm curious why don't use class/extends syntax.  Is it too verbose?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jarek Foksa  
View profile  
 More options Jan 24 2012, 12:31 pm
From: Jarek Foksa <ja...@kiwi-themes.com>
Date: Tue, 24 Jan 2012 18:31:51 +0100
Local: Tues, Jan 24 2012 12:31 pm
Subject: Re: [coffeescript] Why is function binding not the default?

> Now I'm curious why don't use class/extends syntax.  Is it too verbose?

After having read this [1] article several times, I conclued that prototypical
inheritance done with Object.create() is the most elegant approach.

In JavaScript and CoffeeScript one object inherits from another object,
"class ... extends" syntax from CS introduces another concept which is
in my opinion unnecessary.

CoffeeScript classes are actually less verbose than prototypes [2], but
they hide the true nature of the language.

[1] http://killdream.github.com/blog/2011/10/understanding-javascript-oop/
[2] https://gist.github.com/1671263


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile  
 More options Jan 24 2012, 12:55 pm
From: Mark Hahn <m...@hahnca.com>
Date: Tue, 24 Jan 2012 09:55:07 -0800
Local: Tues, Jan 24 2012 12:55 pm
Subject: Re: [coffeescript] Why is function binding not the default?

If you think in OOPS then use prototypes.  If you think in functions then
use closures.  I used to think in OOPS but after using node for over a year
my brain has warped to functions.

The beauty of functions is that you don't have to plan ahead.  You just
start writing the functions you need and as the code grows you realize you
are using closures without thinking.  It is similar to the revolution in
NOSQL databases.  Let your structure grow organically instead of trying to
plan in advance.

Refactor, refactor, refactor, and don't live with early bad decisions.  And
of course the less early decisions you have to make the less early bad
decisions you will have.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 24 2012, 1:03 pm
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 24 Jan 2012 10:03:02 -0800 (PST)
Local: Tues, Jan 24 2012 1:03 pm
Subject: Re: [coffeescript] Why is function binding not the default?

Here's more food for thought on closure style vs. more-class-centric style.  The context here is Ruby/Clojure, but I think the principles apply to CS/JS as well:

http://vimeo.com/34972874


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Brody  
View profile  
 More options Jan 24 2012, 3:11 pm
From: Chris Brody <chris.br...@gmail.com>
Date: Tue, 24 Jan 2012 21:11:01 +0100
Local: Tues, Jan 24 2012 3:11 pm
Subject: Re: [coffeescript] Why is function binding not the default?
Steve, this is really nice, it would be great if someone could put
these in CoffeeScript for those who don't really understand Ruby or
Clojure (myself included).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 24 2012, 3:28 pm
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 24 Jan 2012 12:28:56 -0800 (PST)
Local: Tues, Jan 24 2012 3:28 pm
Subject: Re: [coffeescript] Why is function binding not the default?

I'm not sure exactly what you mean, but I think you're saying that it would be nice to have some kind of write-up/talk that goes into this topic in more depth, more from a CS/JS perspective?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Brody  
View profile  
 More options Jan 24 2012, 3:34 pm
From: Chris Brody <chris.br...@gmail.com>
Date: Tue, 24 Jan 2012 21:34:22 +0100
Local: Tues, Jan 24 2012 3:34 pm
Subject: Re: [coffeescript] Why is function binding not the default?
Yes. Also on the Vimeo page, Brian Marick also has some videos about
monads, a very powerful concept in Haskell, and I am reading a very
interesting post about monads for Javascript:
http://amix.dk/blog/post/19509


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 24 2012, 4:33 pm
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 24 Jan 2012 13:33:48 -0800 (PST)
Local: Tues, Jan 24 2012 4:33 pm
Subject: Re: [coffeescript] Why is function binding not the default?

Chris, maybe you'll find this interesting.

Here are three different approaches to creating objects in CoffeeScript.

closure style: 
  http://bit.ly/zJCEPz 
  http://bit.ly/yGPDNT

"class" feature:
  http://bit.ly/wvVMx5

namespaced functions:
  http://bit.ly/ArTsry

Here's what I like about each style:

closure style: feels JS-like to me and automatically gives you private functions
class style: familiar syntax for folks coming from Python/Ruby/Java
namespaced functions: most flexible, functions aren't tied to any particular object 

The last example is somewhat inspired by various Clojure talks I've heard, although it's my own interpretation, not necessarily the FP party line.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Brody  
View profile  
 More options Jan 24 2012, 6:03 pm
From: Chris Brody <chris.br...@gmail.com>
Date: Wed, 25 Jan 2012 00:03:57 +0100
Local: Tues, Jan 24 2012 6:03 pm
Subject: Re: [coffeescript] Why is function binding not the default?
Yes, the closure style looks kinda like something I saw in LISP where
I had lost the link, definitely good examples.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
karlseg...@gmail.com  
View profile  
 More options Jan 24 2012, 8:18 pm
From: karlseg...@gmail.com
Date: Tue, 24 Jan 2012 17:18:38 -0800 (PST)
Local: Tues, Jan 24 2012 8:18 pm
Subject: Re: Why is function binding not the default?

I've wondered this myself. For me, fat arrows is far more natural. Relying
on the behavior of *not* having function binding is cryptic. It's unclear
to me why you'd want this to change to something potentially unrelated.

Karl


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jan 31 2012, 11:48 am
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 31 Jan 2012 08:48:01 -0800 (PST)
Local: Tues, Jan 31 2012 11:48 am
Subject: Re: [coffeescript] Re: Why is function binding not the default?

In DOM programming sometimes the element is passed as "this" to the functions, so you want to use the skinny arrow and then keep track of "self" via closure.

On the server side, I would think that you'd tend not to have APIs that use "this", so you would generally use the fat arrow there if you are using classes.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »