Issue #11256 has been updated by Eregon (Benoit Daloze).


Just my opinion, but I think the shortcut syntax is going to cause more confusion than it would help.
`&` as argument without a `&` as a parameter looks very weird to me (it's like `it` in other languages, I would strongly advise against such magic).
I argue adding this makes Ruby less readable as a language.

This only saves one character in the definition, and it's not hard to name a block: &b or &block,
that's what the Ruby code out there uses and is clear *because of it*.
Moreover, it's inconsistent with arguments which must be named to be passed (except via zsuper):
`foo(*)` does not work as a call, and `def meth(*)` means ignore arguments, which is meaningless for blocks (just omitting &b is enough to ignore a block).

This also seems to conflict with one of the nicer proposals for short block notations like
enum.map(&.to_s.upcase.ljust(3)), a much more general and useful feature than this shortcut,
which only applies for a few methods forwarding the block and saves 2 character per forwarding method.

Also, the original poster started with "since capturing a block into a proc is slow: foo(&block)".
There is no such reason anymore, and I see no clear motivation of why such a special edge-case syntax is worth adding.

From the developer meeting notes, [Feature #11256] anonymous block forwarding:
Matz: itíăs a good property to avoid naming variables.  Also I personaly like it.  However prompting such name-less programming might let people write cryptic codes.
Matz: hmmí─ Made up my mind. Accepted.

I agree it is cryptic and moreover argue it has little use, is inconsistent with other arguments and likely to cause syntax restrictions for other features.

@bughit Could you explain your motivation for this shortcut now that the performance is no longer a concern?
I agree `foo{yield}` was not nice, but is it worth to have `foo(&) foo(1, 2, &)` over `foo(&b) foo(1, 2, &b)` ?

@matz Could you detail your opinion and reconsider?

----------------------------------------
Feature #11256: anonymous block forwarding
https://bugs.ruby-lang.org/issues/11256#change-68410

* Author: bughit (bug hit)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: next minor
----------------------------------------
since capturing a block into a proc is slow: foo(&block)
and creating chains of blocks is kind of ugly and ultimately also inefficient: foo{yield}
why not allow block forwarding without capturing: foo(&) foo(1, 2, &)



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