Terminology: “non-method function”

# Axel Rauschmayer (13 years ago)

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

Thanks!

Axel

# Mark S. Miller (13 years ago)

"Non-exophoric" is probably too obscure ;)

# Allen Wirfs-Brock (13 years ago)

On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

How about:

procedure - call "callable" object method - a procedure that has a dynamic this (or super) dependency function - a procedure that does not have a dynamic this dependency detached method - a method that has not been associated with an object via Object.defineMethod

FunctionDeclarations and FunctionExpressions may be used to define either methods or functions. Arrow Function expression only define functions Concise method definitions in object literals and class definitions may define either methods or functions

It's messy, but emphasizes that the important thing is what the function depends upon rather than which syntactic form was used to define it.

# Axel Rauschmayer (13 years ago)

Endophoric? It would make linguists happy. ;-)

# Axel Rauschmayer (13 years ago)

On Apr 11, 2012, at 2:02 , Allen Wirfs-Brock wrote:

On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

How about:

procedure - call "callable" object method - a procedure that has a dynamic this (or super) dependency function - a procedure that does not have a dynamic this dependency detached method - a method that has not been associated with an object via Object.defineMethod

I like it. If it wasn’t JavaScript, “function” would clearly be the best name for “a procedure that does not have a dynamic this dependency”. However, in JS we have:

 callableObject instanceof Function

Thus, how about the following:

  • Function: a callable object
  • Method: A function that has a dynamic this (or super) dependency.
  • Callback: A function that does not have a dynamic this dependency.

Not ideal (and in some ways, not as precise), but possibly less confusing.

Interestingly, that would make Math.* (etc.) callbacks, not methods. That works, because Math is just a namespace.

FunctionDeclarations and FunctionExpressions may be used to define either methods or functions. Arrow Function expression only define functions

The following is the messy one:

Concise method definitions in object literals and class definitions may define either methods or functions

Clearly, one’s‚ intention is to define a method. But we may have to live with that, because it’s probably better to categorize callable objects according to some trait of theirs and not according to how they are used at the moment. (I’m not 100% sure, though.) Definitions using the latter approach would be “a function that is the value of a property” or “a function-valued property”.

# Axel Rauschmayer (13 years ago)

Or, if we could somehow express that a “non-method” has no dynamic dependencies and e.g. call it “static function” or “lexical function”.

# Alex Russell (13 years ago)

On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:

On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

How about:

procedure - call "callable" object method - a procedure that has a dynamic this (or super) dependency function - a procedure that does not have a dynamic this dependency detached method - a method that has not been associated with an object via Object.defineMethod

What in the world would "defineMethod" do?

The confusing nature of the word "method" seems not to be cleared up by this. How about "bound" and "unbound" functions? Their iterability might bump them into "method" category if bound, but I think that's still just going to confuse non-JS folk.

FunctionDeclarations and FunctionExpressions may be used to define either methods or functions. Arrow Function expression only define functions Concise method definitions in object literals and class definitions may define either methods or functions

It's messy, but emphasizes that the important thing is what the function depends upon rather than which syntactic form was used to define it.

Allen


es-discuss mailing list es-discuss at mozilla.org, mail.mozilla.org/listinfo/es-discuss

-- Alex Russell slightlyoff at google.com slightlyoff at chromium.org alex at dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723

# Axel Rauschmayer (13 years ago)

On Apr 11, 2012, at 12:37 , Alex Russell wrote:

On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:

On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

How about:

procedure - call "callable" object method - a procedure that has a dynamic this (or super) dependency function - a procedure that does not have a dynamic this dependency detached method - a method that has not been associated with an object via Object.defineMethod

What in the world would "defineMethod" do?

For super to work, a function needs a reference to the object that it is stored in. In the current object literal proposal [1], an object literal does it for you. If you don’t use an object literal, you need defineMethod.

The confusing nature of the word "method" seems not to be cleared up by this. How about "bound" and "unbound" functions? Their iterability might bump them into "method" category if bound, but I think that's still just going to confuse non-JS folk.

I would make the following distinction: .#1 Intended use: non-method (callback? subroutine?) versus method. .#2 Implementation technique: bound function versus unbound function.

ES.next will shield you from the fact that you have to bind functions for them to work as expected as callbacks. I’m looking for a term that explains non-methods at #1 to people who are not familiar with JavaScript.

[1] harmony:object_literals

# Rick Waldron (13 years ago)

On Wednesday, April 11, 2012 at 6:37 AM, Alex Russell wrote:

On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:

On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Any ideas?

How about:

procedure - call "callable" object method - a procedure that has a dynamic this (or super) dependency function - a procedure that does not have a dynamic this dependency detached method - a method that has not been associated with an object via Object.defineMethod

What in the world would "defineMethod" do?

The confusing nature of the word "method" seems not to be cleared up by this. How about "bound" and "unbound" functions? Their iterability might bump them into "method" category if bound, but I think that's still just going to confuse non-JS folk.

This is actually how most JS devs, that I regularly speak with, describe the functions you're describing: constructor, bound/unbound function, method.

# Peter van der Zee (13 years ago)

On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer <axel at rauschma.de> wrote:

What is a good term for functions that don’t have/use dynamic this?

A bound function?

# Allen Wirfs-Brock (13 years ago)

On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:

On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer <axel at rauschma.de> wrote:

What is a good term for functions that don’t have/use dynamic this?

A bound function?

I'm leaning in that direction. A bound function has an unbound (dynamic) this while a bound function has a bound (fixed) this.

To further clarify this it might be useful to better differentiate binding this from currying the arguments.

We might do this by adding a new Function.prototype.curry function that doesn't have a this value as its first argument.

You would then fn.curry(1,2)

If you want to create a curried function from fn with 1 and 2 as the first two fn arguments. and:

fn.bind(foo)

if you want to created a bound version of fn where this is bound to the value of foo.

The semantics of

fn.bind(foo,1,2)

could then be explained as being equivalent to

fn.bind(foo).curry(1,2)
# Axel Rauschmayer (13 years ago)

Great idea. Do we need similar this-less variants for call and apply? Probably not, the former is just a normal function call. The latter can by handled by the spread operator.

IIRC, what one actually does here is not currying, but partial application. However, I don’t see any good method name being derived from “partial application”.

# Domenic Denicola (13 years ago)

We use Function.prototype.partial in our codebase. We consider Function.prototype.papply but thought that would be too confusing with Function.prototype.apply.

# John J Barton (13 years ago)

On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Your combination 'don't have/use' confuses me. A function declaration does not have a 'this', dynamic or not, but it can use 'this' and expect it to be bound dynamically. A function object created from the function declaration can have 'this', but only if it is bound, which in my understanding is therefore not dynamic. To me 'having a dynamic this' is an oxymoron: if you have it, then it ain't dynamic.

Can you un-confuse me?

jjb

# Allen Wirfs-Brock (13 years ago)

(corrected a pretty obvious typo in the first sentence)

On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:

On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer <axel at rauschma.de> wrote:

What is a good term for functions that don’t have/use dynamic this?

A bound function?

I'm leaning in that direction. A unbound function has an unbound (dynamic) this while a bound function has a bound (fixed) this.

To further clarify this it might be useful to better differentiate binding this from currying the arguments.

We might do this by adding a new Function.prototype.curry function that doesn't have a this value as its first argument.

You would then fn.curry(1,2)

If you want to create a curried function from fn with 1 and 2 as the first two fn arguments. And:

fn.bind(foo)

if you want to create a bound version of fn where this is bound to the value of foo.

The semantics of

fn.bind(foo,1,2)

could then be explained as being equivalent to

fn.bind(foo).curry(1,2)

# Wes Garland (13 years ago)

From a developer's POV - the terms bound/unbound makes a create deal of

sense, since already have bind, which effectively turns an unbound function into a bound function. It basically completes the thought and makes it easy to explain.

Heck, it even makes this behaviour easy to explain:

function ABC() { this.hello = "world"; } ABC.prototype.def = function() { alert(this.hello) }; window.onclick = new ABC().def;

Q: Why does my program alert undefined? A: The default behaviour for an event handler is to bind the event itself as 'this'. If you wanted that program to alert "world", you should have used a bound function instead.

# Rick Waldron (13 years ago)

On Wed, Apr 11, 2012 at 4:32 PM, Wes Garland <wes at page.ca> wrote:

From a developer's POV - the terms bound/unbound makes a create deal of sense, since already have bind, which effectively turns an unbound function into a bound function. It basically completes the thought and makes it easy to explain.

Absolutely agree

Heck, it even makes this behaviour easy to explain:

function ABC() { this.hello = "world"; } ABC.prototype.def = function() { alert(this.hello) }; window.onclick = new ABC().def;

Q: Why does my program alert undefined? A: The default behaviour for an event handler is to bind the event itself as 'this'.

Just to avoid any confusion, you'll actually get the event.currentTarget as |this|

# Axel Rauschmayer (13 years ago)

On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer <axel at rauschma.de> wrote: What is a good term for functions that don’t have/use dynamic this? “Non-method function” defines them by what they aren’t, I would like a positive definition. I’ve considered the term “pure function”, but the adjective “pure” is already heavily overloaded, especially in functional programming.

Your combination 'don't have/use' confuses me. A function declaration does not have a 'this', dynamic or not, but it can use 'this' and expect it to be bound dynamically. A function object created from the function declaration can have 'this', but only if it is bound, which in my understanding is therefore not dynamic. To me 'having a dynamic this' is an oxymoron: if you have it, then it ain't dynamic.

Can you un-confuse me?

I was thinking of the function’s “activation record” where a this field is part of the ExecutionContext.

Maybe a better way is to ask: “What is a good term for functions that have no use for their own this, that want to access the this of their surrounding scope?”

I find human language tricky here...