ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:43439] [ruby-trunk - Feature #4475][Assigned] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
@ 2012-03-18 10:05 ` nahi
  2012-11-20 12:26 ` [ruby-core:49705] [ruby-trunk - Feature #4475] " mame (Yusuke Endoh)
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: nahi @ 2012-03-18 10:05 UTC (permalink / raw)
  To: ruby-core


Issue #4475 has been updated by nahi.

Description updated
Category set to core
Status changed from Open to Assigned
Assignee set to matz


----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-24906

Author: jordi
Status: Assigned
Priority: Normal
Assignee: matz
Category: core
Target version: 


=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end



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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:49705] [ruby-trunk - Feature #4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
  2012-03-18 10:05 ` [ruby-core:43439] [ruby-trunk - Feature #4475][Assigned] default variable name for parameter nahi
@ 2012-11-20 12:26 ` mame (Yusuke Endoh)
  2018-04-19  7:51 ` [ruby-core:86598] [Ruby trunk Feature#4475] " knu
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-20 12:26 UTC (permalink / raw)
  To: ruby-core


Issue #4475 has been updated by mame (Yusuke Endoh).

Target version set to next minor


----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-33229

Author: jordi (jordi polo)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end



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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:86598] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
  2012-03-18 10:05 ` [ruby-core:43439] [ruby-trunk - Feature #4475][Assigned] default variable name for parameter nahi
  2012-11-20 12:26 ` [ruby-core:49705] [ruby-trunk - Feature #4475] " mame (Yusuke Endoh)
@ 2018-04-19  7:51 ` knu
  2018-04-19 11:42 ` [ruby-core:86607] " matz
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: knu @ 2018-04-19  7:51 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by knu (Akinori MUSHA).


I would like the feature, but we have many things to think about.

We would not be able to make "it" a reserved keyword because that would destroy all existing RSpec code written in tens of thousands of projects.

If "it" were to be implemented as a method, how could we make it work inside of a BasicObject instance?  What if a method of the same name was defined?

If "it" were to be implemented as a local variable, should its name be included in `local_variables`?

All things considered, I guess the variable name would have to be $-something, if any.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-71554

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:86607] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-04-19  7:51 ` [ruby-core:86598] [Ruby trunk Feature#4475] " knu
@ 2018-04-19 11:42 ` matz
  2018-09-13  5:44 ` [ruby-core:88969] " niinikazuki
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: matz @ 2018-04-19 11:42 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by matz (Yukihiro Matsumoto).


This is a very interesting idea but at the same time, it's difficult to keep compatibility.
At least simple addition of `it` does not work well.

Matz.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-71564

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:88969] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-04-19 11:42 ` [ruby-core:86607] " matz
@ 2018-09-13  5:44 ` niinikazuki
  2018-11-06 14:15 ` [ruby-core:89723] " shevegen
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: niinikazuki @ 2018-09-13  5:44 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by long_long_float (和生 新美).


I have one idea. We can use `\it` (backslash-it) or `\1` instead of `it`. `\1` means the first argument and `\n` refers `n`th argument.

`\`-something is not used, but `\` means line continuation.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-74000

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:89723] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-09-13  5:44 ` [ruby-core:88969] " niinikazuki
@ 2018-11-06 14:15 ` shevegen
  2018-11-06 14:33 ` [ruby-core:89724] " hanmac
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: shevegen @ 2018-11-06 14:15 UTC (permalink / raw)
  To: ruby-core

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


I also like the idea in principle, largely because I can relate to
it.

For example consider code like this:

    object_that_responds_to_each.each {|x|
    object_that_responds_to_each.each {|this_file|

Both variants essentially do the same here, e. g. we iterate over
a collection, and we refer to the content. In the first case, I
use x as name; in the second, I use the longer this_file.

The second variant is a bit more understandable, I think, e. g.
if we iterate over the content of a directory, such as vir Dir['*']
or something like that.

The first variant, however had, is something I use A LOT, and the
reason is actually because it is shorter and simpler to type. There
are trade-offs between readability and ease-of-use, and since I am
quite a lazy person, I often use the first variant. (I do so less
when there is more than one block parameter, but sometimes I do
too, such as via **iterator.each {|a, b, c, d] }** ).

Matz said that compatibility is an issue, but if we ignore this for
the moment, I really think that the proposal is a very interesting
one. So I support the idea behind the suggestion.

As for the specific syntax change such as in:

    Account.all.each { |a| my_account << a.money }
    Account.all.each { my_account << it.money } 

I have no particular pro or con opinion. I think the first variant,
while longer, is more explicit; in the second variant there is a
bit more "magic", unless we know that "it" would refer to the first
block parameter. I am not sure if "it" is the ideal name, but I think
the idea has merits on its own, irrespective of which name is chosen.
(May have to be some special object perhaps, that is like an array,
so we could do ... it[0] it[1] too... and perhaps also it.method_call_here,
but again, these are mostly specifics I think.)

Also I would like to mention that in the much longer case, such as 
this one here:

    object_that_responds_to_each.each {|this_file|

I may have more variables like:

    object_that_responds_to_each.each {|this_file, that_directory, that_thing|

And previously I also wanted a programmable way to refer to the first,
second, and third block parameter, something short like the regex $1, $2, $3,
which are one of the few global variables I like and use, since it is so trivial
to refer to them. I also wanted to have this for block parameters, but I was
unable to come up with a good syntax proposal. (All proposals should ideally
be short, because if they are long then they have a smaller net benefit.)

Anyway, apologies for the length of my comment; I think the idea is a good 
one. If it can not happen before ruby 3.x, perhaps we can aim for it in 
a long path towards ruby 4.x (if we can have more incompatibilites along 
the way).

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-74766

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:89724] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-11-06 14:15 ` [ruby-core:89723] " shevegen
@ 2018-11-06 14:33 ` hanmac
  2019-01-19  5:58 ` [ruby-core:91171] " merch-redmine
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: hanmac @ 2018-11-06 14:33 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by Hanmac (Hans Mackowiak).


shevegen (Robert A. Heiler) wrote:
> The first variant, aka the variant with "x", or any other single letter, including
> "_", is something I use A LOT, and the reason is actually because it is shorter and
> simpler to type for me.

"_" is special there. it doesn't cause Syntax Error
like you can do this `iterator.each {|a, _, c, _] }`
but `iterator.each {|a, x, c, x] }` does  crash

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-74767

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91171] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-11-06 14:33 ` [ruby-core:89724] " hanmac
@ 2019-01-19  5:58 ` merch-redmine
  2019-02-07  7:35 ` [ruby-core:91458] " matz
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: merch-redmine @ 2019-01-19  5:58 UTC (permalink / raw)
  To: ruby-core

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


matz (Yukihiro Matsumoto) wrote:
> This is a very interesting idea but at the same time, it's difficult to keep compatibility.
> At least simple addition of `it` does not work well.

If we want to support implicit block arguments, in order to best keep compatibility, we would probably want to add support for new syntax, using something that is currently a syntax error. knu mentioned $-something, but I think in most cases that would not be a syntax error. One possible option is a bare `@` for the implicit block argument:

~~~ruby
Account.all.each { my_account << @.money }
~~~

This could be extended to support multiple block arguments:

~~~ruby
{1=>2, 3=>4}.map { @1 + @2 }
# => [3, 7]
~~~

I'm not sure it's a good idea to support this, especially for multiple block arguments, because it can make code harder to understand.  In a lot of cases, variable names used in blocks are helpful when reading code to understand what the code is doing.  Granted, if you are using single letter variable names for block arguments, switching to this syntax for implicit arguments would not result in much loss of understanding.

Another issue with implicit block arguments would be arity:

~~~ruby
lambda{ @ }.arity # 0 or 1?
lambda{ [@1, @2] }.arity # 0 or 2?
lambda{ @2 }.arity # 0 or 2?
s = '@2'
lambda{ eval s }.arity # ???
~~~

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-76400

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91458] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2019-01-19  5:58 ` [ruby-core:91171] " merch-redmine
@ 2019-02-07  7:35 ` matz
  2019-02-07 12:48   ` [ruby-core:91470] " Ale Miralles
  2019-02-08 16:35 ` [ruby-core:91497] " janfri26
                   ` (11 subsequent siblings)
  20 siblings, 1 reply; 23+ messages in thread
From: matz @ 2019-02-07  7:35 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by matz (Yukihiro Matsumoto).


I still feel weird when I see `@` and `@1` etc. Maybe I will get used to it after a while.
I need time.

Matz.


----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-76718

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91470] Re: [Ruby trunk Feature#4475] default variable name for parameter
  2019-02-07  7:35 ` [ruby-core:91458] " matz
@ 2019-02-07 12:48   ` Ale Miralles
  2019-02-07 12:55     ` [ruby-core:91471] " Ale Miralles
  0 siblings, 1 reply; 23+ messages in thread
From: Ale Miralles @ 2019-02-07 12:48 UTC (permalink / raw)
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 2099 bytes --]

Kotlin has it, too. It's a nice feature. In a pet language of mine, I added
the index as an "implicit" argument, too. Something like this:

elements  = ["foo", "bar", "baz"]
elements.each {
  puts "Element at index #{idx} has value #{it}."
}

"Element at index 0 has value foo."
"Element at index 1 has value bar."
etc....

I think it would be handy to have that in Ruby.

~ Ale Miralles.
http://amiralles.com.ar



On Thu, Feb 7, 2019 at 4:36 AM <matz@ruby-lang.org> wrote:

> Issue #4475 has been updated by matz (Yukihiro Matsumoto).
>
>
> I still feel weird when I see `@` and `@1` etc. Maybe I will get used to
> it after a while.
> I need time.
>
> Matz.
>
>
> ----------------------------------------
> Feature #4475: default variable name for parameter
> https://bugs.ruby-lang.org/issues/4475#change-76718
>
> * Author: jordi (jordi polo)
> * Status: Assigned
> * Priority: Normal
> * Assignee: matz (Yukihiro Matsumoto)
> * Target version:
> ----------------------------------------
> =begin
>
> There is a very common pattern in Ruby:
>
>  object.method do |variable_name|
>   variable_name doing something
>  end
>
>  Many times in fact the name of the object is so self explanatory that we
> don't care about the name of the variable of the block. It is common to see
> things like :
>
>  @my_sons.each { |s| s.sell_to_someone }
>
> or
>
>  Account.all.each { |a|  my_account << a.money }
>
>
>  People tend to choose s or a because we have the class or the object name
> just there to remind you about the context.
>
>
> I would like to know if can be a good idea to have a default name for that
> parameter. I think it is Groovy that does something like:
>
>   Account.all.each { my_account << it.money }
>
> Where it is automagically filled and it doesn't need to be declared.
>
> I think it is as readable or more (for newbies who don't know what is ||)
> and we save some typing :)
>
>
> =end
>
>
>
>
> --
> 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>
>

[-- Attachment #1.2: Type: text/html, Size: 3305 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91471] Re: [Ruby trunk Feature#4475] default variable name for parameter
  2019-02-07 12:48   ` [ruby-core:91470] " Ale Miralles
@ 2019-02-07 12:55     ` Ale Miralles
  0 siblings, 0 replies; 23+ messages in thread
From: Ale Miralles @ 2019-02-07 12:55 UTC (permalink / raw)
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 2420 bytes --]

Also, I volunteer to (try to) implement it if you think that is something
that worth having in Ruby.

~ Ale Miralles
http://amiralles.com.ar

On Thu, Feb 7, 2019 at 9:48 AM Ale Miralles <amiralles.net@gmail.com> wrote:

> Kotlin has it, too. It's a nice feature. In a pet language of mine, I
> added the index as an "implicit" argument, too. Something like this:
>
> elements  = ["foo", "bar", "baz"]
> elements.each {
>   puts "Element at index #{idx} has value #{it}."
> }
>
> "Element at index 0 has value foo."
> "Element at index 1 has value bar."
> etc....
>
> I think it would be handy to have that in Ruby.
>
> ~ Ale Miralles.
> http://amiralles.com.ar
>
>
>
> On Thu, Feb 7, 2019 at 4:36 AM <matz@ruby-lang.org> wrote:
>
>> Issue #4475 has been updated by matz (Yukihiro Matsumoto).
>>
>>
>> I still feel weird when I see `@` and `@1` etc. Maybe I will get used to
>> it after a while.
>> I need time.
>>
>> Matz.
>>
>>
>> ----------------------------------------
>> Feature #4475: default variable name for parameter
>> https://bugs.ruby-lang.org/issues/4475#change-76718
>>
>> * Author: jordi (jordi polo)
>> * Status: Assigned
>> * Priority: Normal
>> * Assignee: matz (Yukihiro Matsumoto)
>> * Target version:
>> ----------------------------------------
>> =begin
>>
>> There is a very common pattern in Ruby:
>>
>>  object.method do |variable_name|
>>   variable_name doing something
>>  end
>>
>>  Many times in fact the name of the object is so self explanatory that we
>> don't care about the name of the variable of the block. It is common to see
>> things like :
>>
>>  @my_sons.each { |s| s.sell_to_someone }
>>
>> or
>>
>>  Account.all.each { |a|  my_account << a.money }
>>
>>
>>  People tend to choose s or a because we have the class or the object
>> name just there to remind you about the context.
>>
>>
>> I would like to know if can be a good idea to have a default name for
>> that parameter. I think it is Groovy that does something like:
>>
>>   Account.all.each { my_account << it.money }
>>
>> Where it is automagically filled and it doesn't need to be declared.
>>
>> I think it is as readable or more (for newbies who don't know what is ||)
>> and we save some typing :)
>>
>>
>> =end
>>
>>
>>
>>
>> --
>> 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>
>>
>

[-- Attachment #1.2: Type: text/html, Size: 3937 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91497] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2019-02-07  7:35 ` [ruby-core:91458] " matz
@ 2019-02-08 16:35 ` janfri26
  2019-02-08 16:55 ` [ruby-core:91498] " merch-redmine
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: janfri26 @ 2019-02-08 16:35 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by janfri (Jan Friedrich).


I like the ampersand prefix of Elixir:

```elixir
Enum.map [1, 2, 3], &(&1 + 2) # => [3, 4, 5]
Enum.reduce [1, 2, 3], &(&1 + &2) # => 6
```

The ampersand (&) relates more to a block in Ruby than an at-sign (@) which is associated with an instance variable context. So my preferred syntax for Ruby would be:

```ruby
[1, 2, 3].map { &1 + 2 } # => [3, 4, 5]
[1, 2, 3].reduce { &1 + &2 } # => 6
```

But I'm not sure if this could be realized without syntax conflicts.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-76757

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91498] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2019-02-08 16:35 ` [ruby-core:91497] " janfri26
@ 2019-02-08 16:55 ` merch-redmine
  2019-03-11  4:47 ` [ruby-core:91743] " matz
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: merch-redmine @ 2019-02-08 16:55 UTC (permalink / raw)
  To: ruby-core

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


janfri (Jan Friedrich) wrote:
> So my preferred syntax for Ruby would be:
> 
> ```ruby
> [1, 2, 3].map { &1 + 2 } # => [3, 4, 5]
> [1, 2, 3].reduce { &1 + &2 } # => 6
> ```
> 
> But I'm not sure if this could be realized without syntax conflicts.

The problem with that is the syntax can be valid Ruby already, so it could break backwards compatibility:

```ruby
class Integer
  def to_proc
    proc{|v| self + v}
  end
end
[1,2,3].map{|x| ([x]*2).map(&1 + 2)}
```

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-76758

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91743] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2019-02-08 16:55 ` [ruby-core:91498] " merch-redmine
@ 2019-03-11  4:47 ` matz
  2019-03-11 14:36 ` [ruby-core:91785] " nobu
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: matz @ 2019-03-11  4:47 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by matz (Yukihiro Matsumoto).

Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)

I accept `@1` idea. @nobu will implement it. Feel free to try it when it is merged.

Matz.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77019

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91785] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2019-03-11  4:47 ` [ruby-core:91743] " matz
@ 2019-03-11 14:36 ` nobu
  2019-03-18 11:42 ` [ruby-core:91865] " shevegen
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: nobu @ 2019-03-11 14:36 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by nobu (Nobuyoshi Nakada).


https://github.com/ruby/ruby/compare/trunk...nobu:feature/4475-numarg

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77060

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91865] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2019-03-11 14:36 ` [ruby-core:91785] " nobu
@ 2019-03-18 11:42 ` shevegen
  2019-03-18 15:43 ` [ruby-core:91868] " richard.schneeman+ruby-lang
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: shevegen @ 2019-03-18 11:42 UTC (permalink / raw)
  To: ruby-core

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


I think @1 @2 is ok, syntax-wise; it reminds me of $1 $2 for regex matching.

The main two advantages I see is that it is short to type; and also easy
to remember.

There is only one thing that I would like to add and this came from examples
I saw elsewhere; in that the suggestion seems to allow us to completely
omit specifying parameters in blocks, like:

    collection.each {|a, b, c|
    }

versus

    collection.each {
    }

Can we use @1 @2 in both variants?

I think I may have had a slightly similar suggestion to the one listed
here above 8 years ago, but my thought was that we'd still have to 
specify the names to the parameter (variables), so I thought we would
use something like:

    collection.each {|long_name_a, long_name_b, long_name_c|
      pp @1
      pp @3
    }

I do not mind either way, by the way - but when it comes to documentation
and also examples, I think it would help to mention it up front which
variant(s) people could use. The best may be to allow flexibility in both
variants, e. g. to specify the name of the parameters, but to also be able
to omit it, while still being able to use the positional targeting here,
such as through @1 @2 and so forth. And, if this is the case, to also 
give an example or two in the main documentation for this functionality.

Thanks.

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77134

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91868] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2019-03-18 11:42 ` [ruby-core:91865] " shevegen
@ 2019-03-18 15:43 ` richard.schneeman+ruby-lang
  2019-03-18 17:12 ` [ruby-core:91870] " bozhidar
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: richard.schneeman+ruby-lang @ 2019-03-18 15:43 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by schneems (Richard Schneeman).


Would it be possible to make this more inline with other "magic" variables? Such as $1 and $2 for regex. Maybe $blockarg1 and $blockarg2?


----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77137

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91870] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2019-03-18 15:43 ` [ruby-core:91868] " richard.schneeman+ruby-lang
@ 2019-03-18 17:12 ` bozhidar
  2019-03-18 22:48 ` [ruby-core:91878] " gray.kemmey
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: bozhidar @ 2019-03-18 17:12 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by bozhidar (Bozhidar Batsov).


I also dislike the use of `@` for this. It looks very weird and evokes strong references to instance variables in my mind. I'm not sure which characters exactly are an option, but I think we should avoid the use of `@`. Will something like `%1` work? (that's what Clojure uses, which `%` being the same as `%1`.

In general I question I lot the need for this and its usefulness, as short names are usually useful only in short blocks with 1/2 params, otherwise the readability of the code is impacted a lot. We already have a good shorthand for blocks with one param (at least in the most common case), so it feels to me we're complicated the parser/syntax without a very strong case for doing so. Many features are useful to some extent, but we should also keep in mind that none of them come for free. 

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77138

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91878] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2019-03-18 17:12 ` [ruby-core:91870] " bozhidar
@ 2019-03-18 22:48 ` gray.kemmey
  2019-03-22  0:19 ` [ruby-core:91919] " harlemsquirrel
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: gray.kemmey @ 2019-03-18 22:48 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by gkemmey (Gray Kemmey).


Is there a reason to do this other than to save some typing? I'm not sure we've proposed any terribly real-world cases here where this made code better.

I feel like we already have some single-character patterns around blocks with one or two arguments, that aren't that onerous to type and still convey meaning. For example:

```ruby
10.times  { |i| ... } # i for index
10.times { |n| ... } # n for number

[1, 2, 3].map { |n| ... } # n for number
[1, 2, 3].map { |e| ... } # e for element

['one', 'two'].map { |s| ... } # s for string

[1, 2, 3].each_with_index { |e, i| ... }  # e for element, i for index

{ }.each { |k, v| ... }  # k for key, v for value

[[], []]each { |r, c| ... } # two-d arrays: r for row, c for column

File.open('') { |f| ... } # f for file
```

For anything more complex, is it bad too *have* to name your arguments?

In no particular order, some downsides I see:

1. It adds some cognitive load to remember the position of arguments. Like in the `{}.each` example -- is `@1` the key or the value? It's obvious when using `k` and `v` which is which.

2. It blurs the line between instance variables.

3. I don't know that we use simple blocks like this *most* of the time, which means, as a newcomer, you won't see this regularly, and it'll be confusing when you do. Think about the first time you saw something like `[1,2,3].reduce(&:+)`. Was that clear to anyone? (*Though in the `&` case, certainly worth the complexity.*)

4. It's always a little strange when things like this aren't 0-based, right?

5. Personally, find it a little jarring to iterate over an array and then use `@1` to reference each element. "At one" just *feels* positional (like an index).

Anyway, this seems like it adds a fair amount of complexity and sacrifices a lot of readability, just to save ~2 characters. Happy to hear why I'm wrong though...

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77146

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91919] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2019-03-18 22:48 ` [ruby-core:91878] " gray.kemmey
@ 2019-03-22  0:19 ` harlemsquirrel
  2019-03-22  0:31 ` [ruby-core:91920] " duerst
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 23+ messages in thread
From: harlemsquirrel @ 2019-03-22  0:19 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by HarlemSquirrel (Kevin McCormack).


As I'm reading through this I am warming up to this idea. However, I would prefer to keep `@` for instance variables. 

Ruby currently does not allow naming variables or methods starting with a number. Could we utilize this?

```ruby
enumerable_object.map { 1a.method(2a) + 3a * 4a  }
```

I might also suggest that the sequence start with `0a` since we have what feels like an "array" of parameters.

```ruby
enumerable_object.map { "#{0a} comes before #{1a}"  }
```

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77251

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91920] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2019-03-22  0:19 ` [ruby-core:91919] " harlemsquirrel
@ 2019-03-22  0:31 ` duerst
  2019-03-22  6:56 ` [ruby-core:91923] " pascal.betz
  2019-03-22 13:11 ` [ruby-core:91932] " mail
  20 siblings, 0 replies; 23+ messages in thread
From: duerst @ 2019-03-22  0:31 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by duerst (Martin Dürst).


For those who want to change anything, I suggest to create new feature issues. It doesn't make sense to continue discussing a closed issue.


----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77252

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91923] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2019-03-22  0:31 ` [ruby-core:91920] " duerst
@ 2019-03-22  6:56 ` pascal.betz
  2019-03-22 13:11 ` [ruby-core:91932] " mail
  20 siblings, 0 replies; 23+ messages in thread
From: pascal.betz @ 2019-03-22  6:56 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by pascalbetz (Pascal Betz).


gkemmey (Gray Kemmey) wrote:
> Is there a reason to do this other than to save some typing? I'm not sure we've proposed any terribly real-world cases here where this made code better.

Exactly my thought: Why? what will this make better or easier? 
IMHO it does exactly the opposite, it makes Ruby harder to read. By introducing @vars that are NOT instance vars. Code will be harder to read and understand (if it has an @ and starts with a number it is this, otherwise it is that). It saves some typing but short block-vars already possible now:

``` ruby
each {|a| puts a} 

vs. 

each { puts @1 })

```

I love ruby because it allows me to write concise and readable code. Naming variables is part of this.

 

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77255

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [ruby-core:91932] [Ruby trunk Feature#4475] default variable name for parameter
       [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
                   ` (19 preceding siblings ...)
  2019-03-22  6:56 ` [ruby-core:91923] " pascal.betz
@ 2019-03-22 13:11 ` mail
  20 siblings, 0 replies; 23+ messages in thread
From: mail @ 2019-03-22 13:11 UTC (permalink / raw)
  To: ruby-core

Issue #4475 has been updated by sos4nt (Stefan Schüßler).


Since this ticket is closed, I've opened a new one to express my concerns:

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

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77263

* Author: jordi (jordi polo)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin

There is a very common pattern in Ruby:

 object.method do |variable_name|
  variable_name doing something  
 end

 Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like :

 @my_sons.each { |s| s.sell_to_someone }

or

 Account.all.each { |a|  my_account << a.money }


 People tend to choose s or a because we have the class or the object name just there to remind you about the context. 


I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like:

  Account.all.each { my_account << it.money } 

Where it is automagically filled and it doesn't need to be declared.  

I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)


=end




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

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2019-03-22 13:11 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
2012-03-18 10:05 ` [ruby-core:43439] [ruby-trunk - Feature #4475][Assigned] default variable name for parameter nahi
2012-11-20 12:26 ` [ruby-core:49705] [ruby-trunk - Feature #4475] " mame (Yusuke Endoh)
2018-04-19  7:51 ` [ruby-core:86598] [Ruby trunk Feature#4475] " knu
2018-04-19 11:42 ` [ruby-core:86607] " matz
2018-09-13  5:44 ` [ruby-core:88969] " niinikazuki
2018-11-06 14:15 ` [ruby-core:89723] " shevegen
2018-11-06 14:33 ` [ruby-core:89724] " hanmac
2019-01-19  5:58 ` [ruby-core:91171] " merch-redmine
2019-02-07  7:35 ` [ruby-core:91458] " matz
2019-02-07 12:48   ` [ruby-core:91470] " Ale Miralles
2019-02-07 12:55     ` [ruby-core:91471] " Ale Miralles
2019-02-08 16:35 ` [ruby-core:91497] " janfri26
2019-02-08 16:55 ` [ruby-core:91498] " merch-redmine
2019-03-11  4:47 ` [ruby-core:91743] " matz
2019-03-11 14:36 ` [ruby-core:91785] " nobu
2019-03-18 11:42 ` [ruby-core:91865] " shevegen
2019-03-18 15:43 ` [ruby-core:91868] " richard.schneeman+ruby-lang
2019-03-18 17:12 ` [ruby-core:91870] " bozhidar
2019-03-18 22:48 ` [ruby-core:91878] " gray.kemmey
2019-03-22  0:19 ` [ruby-core:91919] " harlemsquirrel
2019-03-22  0:31 ` [ruby-core:91920] " duerst
2019-03-22  6:56 ` [ruby-core:91923] " pascal.betz
2019-03-22 13:11 ` [ruby-core:91932] " mail

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