function invocation with just commas for explicit undefined optional arguments in the middle

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

function invocation with just commas for explicit undefined optional arguments in the middle

manuelbarzi
hi

not sure if this proposal is/was already in discussion. didn't find it.

it's about having the chance to invoke a function with just commas where explicit undefined optional arguments at the beginning or in the middle (not the last one, so not to interfere with trailing commas https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas)

agree there's a convention to locate optional arguments at the end in general, but what if this possibility is accepted for exceptional cases where the order of arguments may infer in a function that alternates undefined optional values in its declaration.

so, for example, given a function:

```
function fun(a, b, c, d, e, f) { // optional c and e values }
```

apart from a regular invocation:

```
fun('a', 'b', undefined, 'd', undefined, 'f')
```

being able to invoke it with just commas where explicit undefined optional values:

```
fun('a', 'b',, 'd',, 'f')
```


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Tab Atkins Jr.
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Naveen Chawla
I tend to agree and one thing I like in good code is "glanceability" -

the ability to "glance" and see what's going on.

If I have

doStuff(bar,, foo,, far)

vs

doStuff(bar, foo,, far)

they don't look too different, but really they are. I normally break params into separate lines so I wouldn't have this problem, but there's the risk overall.

I like that a motivational factor for introducing a language feature is "reducing the likelihood of bugs", and in my mind this one seems to very slightly increase it

On Tue, 29 Oct 2019 at 18:49, Tab Atkins Jr. <[hidden email]> wrote:
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Cyril Auburtin
I proposed it a long time ago https://esdiscuss.org/topic/ignoring-arguments

but I agree with Tab Atkins nowadays, it would hurt readability

On Wed, Oct 30, 2019 at 9:34 AM Naveen Chawla <[hidden email]> wrote:
I tend to agree and one thing I like in good code is "glanceability" -

the ability to "glance" and see what's going on.

If I have

doStuff(bar,, foo,, far)

vs

doStuff(bar, foo,, far)

they don't look too different, but really they are. I normally break params into separate lines so I wouldn't have this problem, but there's the risk overall.

I like that a motivational factor for introducing a language feature is "reducing the likelihood of bugs", and in my mind this one seems to very slightly increase it

On Tue, 29 Oct 2019 at 18:49, Tab Atkins Jr. <[hidden email]> wrote:
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Jeremy Martin
I'm not sure I find the reduced readability argument compelling on this one. The alternatives suggested (throwaway variables or crowding meaningful parameters with `undefined`) don't get clean scores on that front either, IMO.

Simply eliding a parameter seems like a nice example of terse/expressive syntax. /2-cents


On Wed, Oct 30, 2019 at 4:21 PM Cyril Auburtin <[hidden email]> wrote:
I proposed it a long time ago https://esdiscuss.org/topic/ignoring-arguments

but I agree with Tab Atkins nowadays, it would hurt readability

On Wed, Oct 30, 2019 at 9:34 AM Naveen Chawla <[hidden email]> wrote:
I tend to agree and one thing I like in good code is "glanceability" -

the ability to "glance" and see what's going on.

If I have

doStuff(bar,, foo,, far)

vs

doStuff(bar, foo,, far)

they don't look too different, but really they are. I normally break params into separate lines so I wouldn't have this problem, but there's the risk overall.

I like that a motivational factor for introducing a language feature is "reducing the likelihood of bugs", and in my mind this one seems to very slightly increase it

On Tue, 29 Oct 2019 at 18:49, Tab Atkins Jr. <[hidden email]> wrote:
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


--
Jeremy Martin
661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Cyril Auburtin
yes true, it's even more annoying with eslint, you have to configure it with https://eslint.org/docs/rules/no-unused-vars#argsignorepattern for example

To be fair I considered this case mostly for `Array.from({length: n}, (,i) => i)`, but it's easier to forget that comma. What's preferable is a whole new syntax for ranges anyway (some people proposed https://github.com/tc39/proposal-slice-notation/pull/32)

So in the end, having to ignore arguments is probably a sign of a 'bad' design, or at least other possible better workarounds

On Thu, Oct 31, 2019 at 5:23 PM Jeremy Martin <[hidden email]> wrote:
I'm not sure I find the reduced readability argument compelling on this one. The alternatives suggested (throwaway variables or crowding meaningful parameters with `undefined`) don't get clean scores on that front either, IMO.

Simply eliding a parameter seems like a nice example of terse/expressive syntax. /2-cents


On Wed, Oct 30, 2019 at 4:21 PM Cyril Auburtin <[hidden email]> wrote:
I proposed it a long time ago https://esdiscuss.org/topic/ignoring-arguments

but I agree with Tab Atkins nowadays, it would hurt readability

On Wed, Oct 30, 2019 at 9:34 AM Naveen Chawla <[hidden email]> wrote:
I tend to agree and one thing I like in good code is "glanceability" -

the ability to "glance" and see what's going on.

If I have

doStuff(bar,, foo,, far)

vs

doStuff(bar, foo,, far)

they don't look too different, but really they are. I normally break params into separate lines so I wouldn't have this problem, but there's the risk overall.

I like that a motivational factor for introducing a language feature is "reducing the likelihood of bugs", and in my mind this one seems to very slightly increase it

On Tue, 29 Oct 2019 at 18:49, Tab Atkins Jr. <[hidden email]> wrote:
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


--
Jeremy Martin
661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Naveen Chawla
Using `undefined` is readable, it's just not as short. But that's my point. Readability should normally trump "shortness" in case they conflict, in my mind, (while both are desirable) simply for the following reason: if something is accidentally misread, it can cause a bug when used or modified, which I think is worse than "having to type/read more". Of course, if a feature is both shorter and readable (e.g. ES6 classes, arrow functions, etc.) then I think it's an easier choice

On Fri, 1 Nov 2019 at 09:11, Cyril Auburtin <[hidden email]> wrote:
yes true, it's even more annoying with eslint, you have to configure it with https://eslint.org/docs/rules/no-unused-vars#argsignorepattern for example

To be fair I considered this case mostly for `Array.from({length: n}, (,i) => i)`, but it's easier to forget that comma. What's preferable is a whole new syntax for ranges anyway (some people proposed https://github.com/tc39/proposal-slice-notation/pull/32)

So in the end, having to ignore arguments is probably a sign of a 'bad' design, or at least other possible better workarounds

On Thu, Oct 31, 2019 at 5:23 PM Jeremy Martin <[hidden email]> wrote:
I'm not sure I find the reduced readability argument compelling on this one. The alternatives suggested (throwaway variables or crowding meaningful parameters with `undefined`) don't get clean scores on that front either, IMO.

Simply eliding a parameter seems like a nice example of terse/expressive syntax. /2-cents


On Wed, Oct 30, 2019 at 4:21 PM Cyril Auburtin <[hidden email]> wrote:
I proposed it a long time ago https://esdiscuss.org/topic/ignoring-arguments

but I agree with Tab Atkins nowadays, it would hurt readability

On Wed, Oct 30, 2019 at 9:34 AM Naveen Chawla <[hidden email]> wrote:
I tend to agree and one thing I like in good code is "glanceability" -

the ability to "glance" and see what's going on.

If I have

doStuff(bar,, foo,, far)

vs

doStuff(bar, foo,, far)

they don't look too different, but really they are. I normally break params into separate lines so I wouldn't have this problem, but there's the risk overall.

I like that a motivational factor for introducing a language feature is "reducing the likelihood of bugs", and in my mind this one seems to very slightly increase it

On Tue, 29 Oct 2019 at 18:49, Tab Atkins Jr. <[hidden email]> wrote:
On Tue, Oct 29, 2019 at 9:06 AM manuelbarzi <[hidden email]> wrote:
> ```
> fun('a', 'b',, 'd',, 'f')
> ```

While this does technically match up with arrays, I find the the array
behavior unreadable and unintuitive (especially with the exception for
the final comma), and I'd prefer that syntax quirk not spread to other
list-like syntax constructs.

Passing `undefined` is simply and easy enough; if it's too long you
can shave off three characters by spelling it `void 0`. Or put a `var
_;` at the top of your script and use that.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


--
Jeremy Martin
661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: function invocation with just commas for explicit undefined optional arguments in the middle

Boris Zbarsky
In reply to this post by Cyril Auburtin
On 11/1/19 5:10 AM, Cyril Auburtin wrote:
> yes true, it's even more annoying with eslint, you have to configure it
> with https://eslint.org/docs/rules/no-unused-vars#argsignorepattern for
> example

That's talking about function _declarations_, whereas the original
proposal in this thread is about function _invocations_.

> To be fair I considered this case mostly for `Array.from({length: n},
> (,i) => i)`

Right, that's a function declaration, not invocation.

-Boris
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss