Forum: Ruby-core [ruby-trunk - Feature #7055][Open] Allow `.foo=` as a synonym of `self.foo=`

Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2012-09-23 10:27
(Received via mailing list)
Issue #7055 has been reported by alexeymuranov (Alexey Muranov).

----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by Eregon (Benoit Daloze) (Guest)
on 2012-09-23 13:06
(Received via mailing list)
Issue #7055 has been updated by Eregon (Benoit Daloze).


It would collide with existing notation:

    h = {}
    .default = 3

    p h # => 3

A dot beginning a line in 1.9 uses the previous statement as a receiver.
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29682

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2012-09-23 14:43
(Received via mailing list)
Issue #7055 has been updated by alexeymuranov (Alexey Muranov).


=begin
Thanks, I didn't know about this!

However, this use of a beginning dot does not excite me:  it does not 
just use the previous statement value as the receiver, it in fact 
continues the previous line, which can also be done be leaving the dot 
on the previous line.

This makes it not clear if a line is over, and is not usable in IRB.

It would make more sense to me if a call with "empty receiver" always 
used either the value returned by the previous line, or the previously 
returned expression value, as the receiver:

  'aa.bbb.cccc'.split('.')
  prefix, suffix = .first, .last # => ['aa', 'cccc']

or

  'aa.bbb.cccc'.split('.')
  prefix, prefix_length = .first, .length # => ['aa', 2]

Well, this is not the original proposal anymore, i didn't mean to ask to 
deprecate the existing behavior.  I am still interested in other 
opinions.
=end

----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29683

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by Eregon (Benoit Daloze) (Guest)
on 2012-09-23 16:15
(Received via mailing list)
Issue #7055 has been updated by Eregon (Benoit Daloze).


alexeymuranov (Alexey Muranov) wrote:
> [...] it does not just use the previous statement value as the receiver, it in 
fact continues the previous line, which can also be done by leaving the dot on the 
previous line.

Yes, indeed, my wording was badly chosen.

alexeymuranov (Alexey Muranov) wrote:
> I am still interested in other opinions.

I think a nicer syntax for setters would be worth adding, but it 
definitely can't be ".setter =".
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29686

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by Eregon (Benoit Daloze) (Guest)
on 2012-09-23 16:20
(Received via mailing list)
Issue #7055 has been updated by Eregon (Benoit Daloze).


... although I guess there is no real use-case for the continuing dot 
with a method ending with "=", so it might be possible to distinguish 
them.
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29687

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2012-09-23 18:23
(Received via mailing list)
Issue #7055 has been updated by alexeymuranov (Alexey Muranov).


I've thought a bit more about this, and in my opinion, using the "empty 
dot" to continue the previous line is a waste of notation.
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29688

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by marcandre (Marc-Andre Lafortune) (Guest)
on 2012-09-24 02:53
(Received via mailing list)
Issue #7055 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

Closing this suggestion, as this would be a compatibility nightmare.
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29691

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2012-09-29 16:28
(Received via mailing list)
Issue #7055 has been updated by alexeymuranov (Alexey Muranov).


Maybe than `@` instead of `self`?

  @.foo = 'bar'

instead of

  self.foo = 'bar'

----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29790

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by stomar (Marcus Stollsteimer) (Guest)
on 2012-09-30 07:57
(Received via mailing list)
Issue #7055 has been updated by stomar (Marcus Stollsteimer).


=begin
I think that would decrease readability of the code quite a lot (even 
more so for the first suggestion) and I don't see ((*any*)) benefit. 
It's only four characters.
=end

----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29801

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2012-09-30 11:07
(Received via mailing list)
Issue #7055 has been updated by alexeymuranov (Alexey Muranov).


@stomar, maybe you are right that `self.foo =` is more readable than 
`@.foo =` or `.foo =`, especially for someone who would see it for the 
first time.  However, then it seems to me that `bar = self.foo()` is 
also more readable than just `bar = foo`. Maybe i do not understand what 
exactly is meant by "readability" here.

I agree that 4 characters is not a lot to be replaced with 1, but if all 
4 were removed, as in the original proposal, i would have liked it.
----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29804

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Posted by stomar (Marcus Stollsteimer) (Guest)
on 2012-09-30 16:40
(Received via mailing list)
Issue #7055 has been updated by stomar (Marcus Stollsteimer).


=begin
A single dot is very unobtrusive. So I just think that `.foo` and `foo` 
resp. `@.foo` and `@foo` would look too similar to be easily 
distinguished, especially when browsing through larger pieces of code.
=end
=end

----------------------------------------
Feature #7055: Allow `.foo=` as a synonym of `self.foo=`
https://bugs.ruby-lang.org/issues/7055#change-29812

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
I propose to make the use of `self` in method calls optional:

  .foo = 'bar'

instead of

  self.foo = 'bar'

This only matters of course for assignment methods, to distinguish a 
method call from creating or setting a local variable.
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.