Should ... be suffix rather than prefix?

# Mark S. Miller (13 years ago)

foo(a, b, ...rest)

vs

foo(a, b, rest...)

Which is clearer?

ES6 has currently agreed on the first. English and Scheme agree on the second.

This question applies to both < harmony:rest_parameters> and <

harmony:spread>.

# Peter van der Zee (13 years ago)

Second...

# Axel Rauschmayer (13 years ago)

Call me crazy, but I’d use postfix for a declaration of a rest parameter and prefix for spreading. To me, prefix feels like it does something, while postfix has more of a declarative feel.

function foo(a, rest...) { bar(...rest); }

Whatever we choose, people will get used to it. So I don’t think it matters much.

# Russell Leggett (13 years ago)

Second...

In fact, I think I've even written a few code examples accidentally using that form because it was just more natural.

# Erik Arvidsson (13 years ago)

FWIW, Python and Ruby uses prefix (the * operator). Java and C++11 uses prefix ... (actually suffix on the type).

My vote is for prefix.

# Jorge (13 years ago)

On Apr 3, 2012, at 10:16 PM, Mark S. Miller wrote:

foo(a, b, ...rest)

vs

foo(a, b, rest...)

Which is clearer?

ES6 has currently agreed on the first. English and Scheme agree on the second.

The second, of course. As in C: the ellipsis always ends the parameters list.

# Allen Wirfs-Brock (13 years ago)

I find the prefix more readable, in both situations.

I read from left to right, and it is clearer when the most semantically important symbol comes as early as possible in that left to right progression.

# Irakli Gozalishvili (13 years ago)

Second feels more intuitive to me

-- Irakli Gozalishvili Web: www.jeditoolkit.com

# Claus Reinke (13 years ago)

foo(a, b, ...rest)

vs

foo(a, b, rest...)

Which is clearer?

The former suggests a special construct that may have a name, the latter suggests a variable of a special kind. But there isn't anything special about the variable (a or b could be Arrays, too), so I find the suffix form misleading.

I found the prefix easy to get used to, and it alerts me that something special is going on with the match or substitution.

Also, doesn't the English form suggest the dotted content to be separate from rest, rather than included in it?

Btw, why three dots? I always find myself writing two dots..

Claus

# Tab Atkins Jr. (13 years ago)

On Wed, Apr 4, 2012 at 7:03 AM, Claus Reinke <claus.reinke at talk21.com> wrote:

Btw, why three dots? I always find myself writing two dots..

Presumably because three dots make an ellipsis, which has roughly the meaning we're aiming for here.

# Claus Reinke (13 years ago)

Btw, why three dots? I always find myself writing two dots..

Presumably because three dots make an ellipsis, which has roughly the meaning we're aiming for here.

True, and I admit to omitting that third dot in natural language as well. But in the context of JS, if I think of ... as the anonymous ellipsis (just leaving something out, no variable binding), then ..var seems natural for the not-quite ellipsis that binds a variable, and ...var feels too long (and too much like natural language ellipsis, which would have no association with the word before or after).

I'll probably manage to adjust once ES6 implementations are more common, but I thought I'd mention it;-)

Claus

# Kyle Murray (13 years ago)

Two dots are (in some contexts) the descendant access operator in E4X, so that might have had something to do with the decision.

# Brendan Eich (13 years ago)

Kyle Murray wrote:

Two dots are (in some contexts) the descendant access operator in E4X, so that might have had something to do with the decision.

Even in plain JS without E4X [1], two dots are one way to access prototype methods of a floating point literal:

js> 42..toString(16) "2a"

and even if unambiguous formally, some readers will find novel uses of .. to be a speedbump. Three to be sure.

In this light, prefix over suffix also wins.

/be

[1] s3.amazonaws.com/data.tumblr.com/tumblr_m1vp6tzTbn1rrf1eeo1_1280.png?AWSAccessKeyId=AKIAI6WLSGT7Y3ET7ADQ&Expires=1334078546&Signature=bbDSaQg103LvcupBfxWSQel%2Fcps%3D

# Andreas Rossberg (13 years ago)

On 3 April 2012 22:16, Mark S. Miller <erights at google.com> wrote:

foo(a, b, ...rest)

vs

foo(a, b, rest...)

Which is clearer?

First, because it is much more apparent that 'rest' is a different beast than the other parameters. The second form "looks" natural but in a rather misleading way.

ES6 has currently agreed on the first. English and Scheme agree on the

second.

There seems to be sufficient precedent in PLs either way. But what would be the equivalent to this construct in the English language? (The second form exists in English syntactically, but with a different meaning.)

# Herby Vojčík (13 years ago)

Andreas Rossberg wrote:

On 3 April 2012 22:16, Mark S. Miller <erights at google.com <mailto:erights at google.com>> wrote:

     foo(a, b, ...rest)

vs

     foo(a, b, rest...)

Which is clearer?

First, because it is much more apparent that 'rest' is a different beast than the other parameters. The second form "looks" natural but in a rather misleading way.

ES6 has currently agreed on the first. English and Scheme agree on
the second.

There seems to be sufficient precedent in PLs either way. But what would be the equivalent to this construct in the English language? (The second

"... (the rest)" Which sort-of convinced me that prefix is the right one.