Issue #16253 has been updated by jeremyevans0 (Jeremy Evans).


The disadvantage I see to this proposal is increased complexity.  Both internal complexity in the implementation, and also more complexity for the user, as this adds more syntax Ruby programmers need to understand.  However, I think the increased complexity for the user is probably offset by the fact that the `...` syntax is simpler than `*a, **kw, &b` and probably more understandable for new Ruby programmers.

The main advantage I see to this proposal is potentially better performance (in CRuby).  Currently, delegating using:

```ruby
  def foo(*a, **o, &b)
    @bar.foo(*a, **o, &b)
  end
```

Causes an array allocation and multiple hash allocations for the delegation itself.  Theoretically, delegating using:

```ruby
  def foo(...)
    @bar.foo(...)
  end
```

should not cause any allocations for the delegation itself.

In terms of `*` vs. `...`, I would go with `...`.  `@bar.foo(*)` doesn't imply to me that it would pass keyword arguments or a block, as `@bar.foo(*a)` wouldn't pass keyword arguments or a block.

I think there are some questions that need to be answered, if we decide to do this.

First, do we allow any other arguments in the method definition?  If so, do we only allow mandatory positional arguments? Do we support optional positional arguments?  I think it wouldn't make sense to support rest, keyword, or block arguments. Supporting mandatory positional arguments makes this more flexible and usable in more places, but also increases complexity.

Second, where we do allow `...` when calling? Is this allowed and does is pass arguments from `foo` to `@bar.foo`?:

```ruby
  def foo(...)
    synchronize do |x|
      @bar.foo(...)
    end
  end
```

Does this code pass arguments that `synchronize` yields to `@bar.foo`:

```ruby
  def foo(...)
    synchronize do |...|
      @bar.foo(...)
    end
  end
```

Is this a `SyntaxError`?:

```ruby
  def foo
    @bar.foo(...)
  end
```

What about:

```ruby
  PR = proc do
    @bar.foo(...)
  end
  def foo(...)
    instance_exec(&PR)
  end
```

If `...` can be implemented such that it improves performance over `*a, **kw, &b` (in CRuby), I think it may be worth adding.  Otherwise, I don't think this is worth adding.

----------------------------------------
Feature #16253: Shorthand "forward everything" syntax
https://bugs.ruby-lang.org/issues/16253#change-82078

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
What about using this:

```ruby
  def foo(*)
    @bar.foo(*)
```

to mean this:

```ruby
  def foo(*a, **o, &b)
    @bar.foo(*a, **o, &b)
```

I used `def foo(*)` because that's currently valid ruby code, but I'm fine with any syntax.

It's like the no-parentheses `super` shorthand, but for any method.

It makes it easier to write correct forwarding code. 

If rubyists must be told they have to change their forwarding code in 2.7 (due to keyword arguments), the pill might be easier to swallow if the change is a reduction rather than an increase in verbosity.

And we'd even be future-proof if an eventual FOURTH kind of parameter is introduced!!!!




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>