ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95427] [Ruby master Feature#16253] Shorthand "forward everything" syntax
Date: Fri, 18 Oct 2019 23:33:43 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-82181.20191018233337.60ffe6699c22304f@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16253.20191015153838@ruby-lang.org

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


ioquatix (Samuel Williams) wrote:
> Here are some real world examples from my code:
> 
> ```
> def self.for(*arguments, &block)
> 	self.new(block, *arguments)
> end
> 
> # Nicer?
> 
> def self.for(..., &block)
> 	self.new(block, ...)
> end
> ```

From reading the last dev meeting log (under `Future work: lead argument handling is postponed`), this will not be supported, at least initially.

> Module to be prepended:
> 
> ```
> module Connection
> 	def initialize(*)
> 		super
> 		
> 		# Other stuff
> 	end
> end
> 
> # Nicer?
> 
> module Connection
> 	def initialize(...)
> 		super(...)
> 		
> 		# Other stuff
> 	end
> end
> ```

I think a bare `super` makes more sense than `super(...)`, and it is backwards compatible.  However, in order to avoid keyword argument separation issues, if the super method accepts keyword arguments, you need to do `def initialize(*, **)` instead of `def initialize(*)` (`def initialize(...)` should also work).

> Many repeated code:
> 
> ```
> def self.split(*arguments, **options)
> 	append Split.new(*arguments, **options)
> end
> 
> # Nicer and more maintainable?
> 
> def self.split(...)
> 	append Split.new(...)
> end
> ```

Definitely looks nicer, so if you don't care about backwards compatibility, it seems like a good change.

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

* 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/

  parent reply	other threads:[~2019-10-18 23:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16253.20191015153838@ruby-lang.org>
2019-10-15 15:38 ` [ruby-core:95338] [Ruby master Feature#16253] Shorthand "forward everything" syntax daniel
2019-10-15 15:53 ` [ruby-core:95340] " eregontp
2019-10-15 17:20 ` [ruby-core:95342] " shevegen
2019-10-16 10:33 ` [ruby-core:95364] " eregontp
2019-10-16 13:05 ` [ruby-core:95366] " daniel
2019-10-16 13:17 ` [ruby-core:95367] " zverok.offline
2019-10-16 16:55 ` [ruby-core:95370] " merch-redmine
2019-10-16 17:32 ` [ruby-core:95371] " daniel
2019-10-18 23:17 ` [ruby-core:95426] " samuel
2019-10-18 23:33 ` merch-redmine [this message]
2019-10-19  2:56 ` [ruby-core:95428] " samuel
2019-10-20 11:56 ` [ruby-core:95437] " nobu
2019-10-20 12:07 ` [ruby-core:95439] " nobu
2019-10-22 19:37 ` [ruby-core:95478] " keystonelemur
2019-11-10 10:27 ` [ruby-core:95773] " eregontp
2019-11-10 10:39 ` [ruby-core:95774] " mame
2019-11-10 21:23 ` [ruby-core:95778] " eregontp
2019-11-10 21:41 ` [ruby-core:95779] " merch-redmine
2019-11-10 22:57 ` [ruby-core:95782] " eregontp
2019-11-27 16:51 ` [ruby-core:95994] " eregontp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-82181.20191018233337.60ffe6699c22304f@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).