Issue #16178 has been updated by shevegen (Robert A. Heiler).


Hmmm. I find underscores to be harder to read in combination with
other parts (e. g. _abc or _123) whereas I use _ quite a bit in my
own code.

I still like @1 @2 @3 etc... - however had, I have to admit that if
the suggestion is to use _1 _2 _3 then I actually would rather prefer
to not add this altogether. ;-)

I think the whole numbered parameters, while I like it in general,
created some problems for people to adjust their mindset into. On
the other hand, since ruby users are not forced to use it, they can
ignore it, which happens with other features too.

zverok wrote:

> Some counter-points (that being said, I dislike the "unnamed parameters"
> idea as a whole

I begin to dislike it mostly due to different syntax use. ;-)

However had, perhaps there should be another discussion at some upcoming
dev meeting. Perhaps not necessarily meant to stop the addition as such,
but to consider it for later addition (or more discussion). Also what
zverok wrote:

> because I am afraid this feature -- being just "shorter" while staying
> imperative

I am not sure what you mean with "imperative" here, but ok.

> will stay in the way of adoption of more promising features like
> &obj.:method, experiments towards proper currying etc.):

I would actually rpefer to not add EITHER numbered parameters and
NEITHER your &obj.:method notation. This may be individual preference,
of course, but I dislike that we may have to look too closely. I am
not sure why you connect these two, though; to me both are totally
independent. And even if numbered parameters are not added, I still
would prefeer there be no &obj.:method notation altogether nor .:
even though I can understand that it enables new possibilities in regards
to writing ruby code. You write awesome code; but on the other hand,
I find it very hard to read and understand.

IMO it may be best for ruby to stay simpler and reject most of these
syntax changes. ;-)

> In your proposal, the last line should be, like

    to_h { [_1[0], _1[1].to_i] } 

I actually dislike this even more than the suggestion for "it". :D

Anyway, I do not want to distract too much, so perhaps there can be
another dev meeting/discussion. Of course matz decides, but this 
becomes a bit difficult here if we inter-connect different features
and proposals with one another; or different syntax. I am still in
the pro-numbered parameters camp in general though, just not as close
to the _numbers variants camp. Good syntax is difficult. :P

----------------------------------------
Bug #16178: Numbered parameters: _1 should be the same as |x| and _0 should not exist
https://bugs.ruby-lang.org/issues/16178#change-81695

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
* ruby -v: ruby 2.7.0dev (2019-09-24T12:57:54Z master 0e84eecc17) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Currently on trunk:
```ruby
array = ["string", 42, [1, 2]]

array.map { |x| x * 2 }
# => ["stringstring", 84, [1, 2, 1, 2]]

array.map { _1 * 2 }
# => ["stringstring", 84, 2]
```

Oops, this trivial code just lost data and completely ignored the element class!
This is clearly contrary to intuition and is very dangerous.

Using `_0` instead has the correct behavior but it's clear we use 1-based indexing for numbered parameters,
and it doesn't solve that `_1` has dangerous behavior.

Basically the current behavior is that `_0` is the same as `|x|` and `_1` is the same as `|x,|`.
`|x,|` is almost never used in Ruby, and for good reasons, it just throws away data/information/the class of the object.
Such a dangerous operation should only be done when it's explicit, and the trailing comma in `|x,|` shows that, but `_1` does not.

So let's make `_1` be `|x|` and remove `_0`.

I am going to be harsh, but this discussion has gone too long without any serious written argument for the current behavior:
I believe it's irrational and irresponsible to have `_1` be `|x,|`, it's just going to lead to nasty bugs.

Try to convince me otherwise.
If not, in one week I want to apply this change.

From the discussion in https://bugs.ruby-lang.org/issues/15723#note-127
and in https://bugs.ruby-lang.org/issues/15708

Some reactions to this behavior in https://twitter.com/eregontp/status/1115318993299083265



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