Re: Proposal: rest operator in middle of array

2019-06-10 Thread guest271314
>
> but imo it really masks the author's intention (in addition to being more
> verbose and less efficient) when compared to:
> ```
> const [...xs, y] = someArray;
> ```


No intention is "masked". Yes, more verbose, though demonstrates that the
expected output is now possible using current version of JavaScript.

"less efficient" is a statement which requires evidence. Compared to what?
How is "efficient" benchmarked and measured and compared?

The proposed solutions for argument lists strike me as less-good.


Again, the term "less-good" is entirely subjective. There is no "good" or
"bad" code, there is only code. The opinion of "good" or "bad" is in the
individual human mind, not the code, and is subject to change from one
moment to the next.


function match(matchers, data = matchers.pop()) {
>   console.log(matchers, data);
> }
> const x = [[1,2],3];
> match(x);
> console.log(x); // [[1,2]], uh oh, x has changed.
> ```


As mentioned in the post, the same pattern as  ```const [[...xs], y =
xs.pop()] = [someArray];``` can be used

```
function match([...matchers], data = matchers.pop()) {
  console.log(matchers, data);
}
const x = [[1,2],3];
match(x);
console.log(x); // [[1,2]] no mutation
```

Each of the examples is already achievable using JavaScript shipped with
the browser. Could not actually determine what the issue is with the
existing code. It is already possible to compose code where the center, or
any argument identifer can be spread to an array. If the input is
individual arguments to a function, those arguments, too, can be converted
to an array within the arguments scope; as it is possible to run functions
in the argument scope which change the current and subsequent parameters.
If the concept is dynamic and arbitrary arguments you can use object
destructuring, default parameters, default values, ```Object.assign()```,
or if necessary, a generator function.

On Mon, Jun 10, 2019 at 11:46 PM Ethan Resnick 
wrote:

> > The proposed pattern is already possible, as demostrated at the code at
> https://esdiscuss.org/topic/proposal-rest-operator-in-middle-of-array#content-2
> .
>
> Sorry, I missed your response earlier!
>
> Regarding
>
> ```
> const [[...xs], y = xs.pop()] = [someArray];
> ```
>
> That works and is quite clever, but imo it really masks the author's
> intention (in addition to being more verbose and less efficient) when
> compared to:
>
> ```
> const [...xs, y] = someArray;
> ```
>
> The proposed solutions for argument lists strike me as less-good.
>
> In the case of `pad`, using one, object-valued argument would make partial
> application impossible, which is essential in most data-last use cases.
>
> In the rewritten version of `match`, I'm not sure how the `pop()` trick is
> helping. If it's valid to pass in the matchers as a single, array-valued
> argument, then the signature can be simply:  `function match(matchers,
> data) { /* .. */ }`. The tricky bit about my original version was that it
> took the matchers passed in as separate arguments, rather than passing in a
> single array of matchers, for reasons that were more convenient in my
> domain.
>
> I don't see how any version of the `pop()` trick can help when there are
> truly multiple optional arguments (a la the `opts` array in `pad`). Also,
> the `pop()` trick could be quite problematic if it ends up mutating the
> user's input, as it would in the given example:
>
> ```
> function match(matchers, data = matchers.pop()) {
>   console.log(matchers, data);
> }
>
> const x = [[1,2],3];
> match(x);
> console.log(x); // [[1,2]], uh oh, x has changed.
> ```
>
>
> On Tue, Jun 11, 2019 at 1:13 AM guest271314  wrote:
>
>> The proposed pattern is already possible, as demostrated at the code at
>> https://esdiscuss.org/topic/proposal-rest-operator-in-middle-of-array#content-2
>> .
>>
>> How does the code at that post specifically not provide the same
>> functionality as proposed?
>>
>> On Mon, Jun 10, 2019 at 9:20 PM Ethan Resnick 
>> wrote:
>>
>>> > This has come up several times and, while it seems pretty intuitive to
>>> me, not everyone seems to agree. You can check the archives for previous
>>> discussions.
>>>
>>> @Andy Perhaps you can provide some links? I found two
>>> 
>>> threads  — both 8
>>> years old — that talked about this, along with one more recent one
>>> 
>>> that didn't get very far. In the first two threads, commenters brought up
>>> one case where the semantics are unclear (i.e., when there are more listed
>>> binding elements than there are elements in the iterable), and there was
>>> some talk about implementation complexity. But there was also some interest
>>> from some big contributors to the spec. So I wonder if it's time to revisit
>>> this?
>>>
>>> > if you want to extend the function with 

Re: Proposal: rest operator in middle of array

2019-06-10 Thread guest271314
The proposed pattern is already possible, as demostrated at the code at
https://esdiscuss.org/topic/proposal-rest-operator-in-middle-of-array#content-2
.

How does the code at that post specifically not provide the same
functionality as proposed?

On Mon, Jun 10, 2019 at 9:20 PM Ethan Resnick 
wrote:

> > This has come up several times and, while it seems pretty intuitive to
> me, not everyone seems to agree. You can check the archives for previous
> discussions.
>
> @Andy Perhaps you can provide some links? I found two
> 
> threads  — both 8
> years old — that talked about this, along with one more recent one
> 
> that didn't get very far. In the first two threads, commenters brought up
> one case where the semantics are unclear (i.e., when there are more listed
> binding elements than there are elements in the iterable), and there was
> some talk about implementation complexity. But there was also some interest
> from some big contributors to the spec. So I wonder if it's time to revisit
> this?
>
> > if you want to extend the function with additional args,
> > then you'll have to retroactively modify all existing calls to avoid
> off-by-one argcount:
>
> @Kai I'm not sure I follow. If the new argument is required, you have to
> modify all existing calls whether the new argument goes at the end or as
> the second to last argument. If the new argument is optional, then adding
> it as the second to last argument doesn't break existing calls at all,
> assuming the function accounts for the fact that the optional arguments are
> all the ones after the initial required ones, and up until (but excluding)
> the last one. The syntax I'm proposing makes adding such extra arguments
> easy. In other words:
>
> ```
> function pad(targetLength, ...opts, data) {
>   const [paddingChar = " "] = opts;
>   // pad data with paddingChar to targetLength;
> }
> ```
>
> would, with the addition of an optional "meta" arg, become:
>
> ```
> function pad(targetLength, ...opts, data) {
>   const [paddingChar = " ", meta = { /* some default */ }] = opts;
>   // pad data with paddingChar to targetLength;
> }
> ```
>
> More importantly, though, this data-last calling pattern has a long
> history, and there are some cases where it's the best solution. My use case
> was similar to the common one, namely, that I was building a data pipeline,
> with the "settings" arguments partially applied from the left to create the
> function to use in each step. (And, in my case, I was building each
> function in a DSL where it would've been very inconvenient to add
> arbitrary-order partial application, even if JS were to add something like
> that .)
>
> Given that functions where the last argument is significant probably
> aren't going away, it'd be nice imo if the JS syntax supported this better.
>
> On Fri, Jun 7, 2019 at 7:11 PM kai zhu  wrote:
>
>> it matters when you have to debug/inherit *other* people's code (and
>> clean up their mess).  i wouldn't enjoy debugging unfamiliar-code that used
>> this feature (admittedly, its my subjective opinion).
>>
>> the maintainability argument stands -- its counter-intuitive in
>> javascript that appending extra args to a function re-arranges
>> arg-positioning and invalidates existing calls.
>>
>> debuggability is subjective i agree.
>>
>> p.s. - in general, i don't see what *real* painpoint rest-operator
>> actually address, that couldn't be solved with `arguments`.
>> variable-arg-length functions are not javascripty -- they frequently
>> require extra ux-workflow transformations like Function.p.apply or
>> Array.p.flatmap to the arguments being passed.
>>
>>
>> On Fri, Jun 7, 2019 at 10:07 AM Isiah Meadows 
>> wrote:
>>
>>> For your maintainability argument: adding extra arguments to those
>>> functions is something I almost never do. And you'd have the same
>>> exact issue with final rest parameters, just in a different position
>>> (in the middle as opposed to in the end).
>>>
>>> For debuggability, I don't see how it'd be a major issue unless you
>>> already have an excessive number of *positional* parameters. In my
>>> experience, the debuggability issues arise approximately when there's
>>> just too many positional parameters, and factoring out the rest
>>> parameter to an array doesn't really help this situation much. (That's
>>> when object destructuring comes in handy.)
>>>
>>> So not convinced either is any different than what it's like today.
>>>
>>> Also, you aren't obligated to use a feature just because it exists - I
>>> hardly ever use proxies, for instance, and I rarely need maps beyond
>>> what objects give me, so I don't normally use them unless I need to
>>> have reference types or mixed types as keys.
>>>
>>> -
>>>

Re: Proposal: rest operator in middle of array

2019-06-10 Thread Ethan Resnick
> This has come up several times and, while it seems pretty intuitive to
me, not everyone seems to agree. You can check the archives for previous
discussions.

@Andy Perhaps you can provide some links? I found two

threads  — both 8 years
old — that talked about this, along with one more recent one

that didn't get very far. In the first two threads, commenters brought up
one case where the semantics are unclear (i.e., when there are more listed
binding elements than there are elements in the iterable), and there was
some talk about implementation complexity. But there was also some interest
from some big contributors to the spec. So I wonder if it's time to revisit
this?

> if you want to extend the function with additional args,
> then you'll have to retroactively modify all existing calls to avoid
off-by-one argcount:

@Kai I'm not sure I follow. If the new argument is required, you have to
modify all existing calls whether the new argument goes at the end or as
the second to last argument. If the new argument is optional, then adding
it as the second to last argument doesn't break existing calls at all,
assuming the function accounts for the fact that the optional arguments are
all the ones after the initial required ones, and up until (but excluding)
the last one. The syntax I'm proposing makes adding such extra arguments
easy. In other words:

```
function pad(targetLength, ...opts, data) {
  const [paddingChar = " "] = opts;
  // pad data with paddingChar to targetLength;
}
```

would, with the addition of an optional "meta" arg, become:

```
function pad(targetLength, ...opts, data) {
  const [paddingChar = " ", meta = { /* some default */ }] = opts;
  // pad data with paddingChar to targetLength;
}
```

More importantly, though, this data-last calling pattern has a long
history, and there are some cases where it's the best solution. My use case
was similar to the common one, namely, that I was building a data pipeline,
with the "settings" arguments partially applied from the left to create the
function to use in each step. (And, in my case, I was building each
function in a DSL where it would've been very inconvenient to add
arbitrary-order partial application, even if JS were to add something like
that .)

Given that functions where the last argument is significant probably aren't
going away, it'd be nice imo if the JS syntax supported this better.

On Fri, Jun 7, 2019 at 7:11 PM kai zhu  wrote:

> it matters when you have to debug/inherit *other* people's code (and clean
> up their mess).  i wouldn't enjoy debugging unfamiliar-code that used this
> feature (admittedly, its my subjective opinion).
>
> the maintainability argument stands -- its counter-intuitive in javascript
> that appending extra args to a function re-arranges arg-positioning and
> invalidates existing calls.
>
> debuggability is subjective i agree.
>
> p.s. - in general, i don't see what *real* painpoint rest-operator
> actually address, that couldn't be solved with `arguments`.
> variable-arg-length functions are not javascripty -- they frequently
> require extra ux-workflow transformations like Function.p.apply or
> Array.p.flatmap to the arguments being passed.
>
>
> On Fri, Jun 7, 2019 at 10:07 AM Isiah Meadows 
> wrote:
>
>> For your maintainability argument: adding extra arguments to those
>> functions is something I almost never do. And you'd have the same
>> exact issue with final rest parameters, just in a different position
>> (in the middle as opposed to in the end).
>>
>> For debuggability, I don't see how it'd be a major issue unless you
>> already have an excessive number of *positional* parameters. In my
>> experience, the debuggability issues arise approximately when there's
>> just too many positional parameters, and factoring out the rest
>> parameter to an array doesn't really help this situation much. (That's
>> when object destructuring comes in handy.)
>>
>> So not convinced either is any different than what it's like today.
>>
>> Also, you aren't obligated to use a feature just because it exists - I
>> hardly ever use proxies, for instance, and I rarely need maps beyond
>> what objects give me, so I don't normally use them unless I need to
>> have reference types or mixed types as keys.
>>
>> -
>>
>> Isiah Meadows
>> cont...@isiahmeadows.com
>> www.isiahmeadows.com
>>
>> On Thu, Jun 6, 2019 at 2:22 PM kai zhu  wrote:
>> >
>> > -1 for maintainability and debuggability
>> >
>> > 1. maintainability
>> > if you want to extend the function with additional args,
>> > then you'll have to retroactively modify all existing calls to avoid
>> off-by-one argcount:
>> >
>> > ```js
>> > // if extending function with additional args
>> > function