https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-05-08T03:35:21ZRuby Issue Tracking SystemRuby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391832013-05-08T03:35:21ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>i am against that, what about methods that are defined in Kernel, but you want when you are inside an BasicObject?<br>
you need something like:<br>
Kernel::Array([])<br>
or<br>
Kernel.Array([])<br>
what does make more sense for you?</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391842013-05-08T05:03:12ZEregon (Benoit Daloze)
<ul></ul><p>Hanmac (Hans Mackowiak) wrote:</p>
<blockquote>
<p>i am against that, what about methods that are defined in Kernel, but you want when you are inside an BasicObject?<br>
you need something like:<br>
Kernel::Array([])<br>
or<br>
Kernel.Array([])<br>
what does make more sense for you?</p>
</blockquote>
<p>You need :: before Kernel, unless you define const_get<br>
::Kernel::Array(3)<br>
And in that case I much prefer<br>
::Kernel.Array(3)<br>
even if it does not look as nice because at least is is clear :: is constant resolution.</p>
<p>This is a weird case due to the upper case first letter, what do you think about:<br>
::Kernel::puts "Hello"<br>
versus<br>
::Kernel.puts "Hello"</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391852013-05-08T08:53:13ZAnonymous
<ul></ul><p>On Wednesday, 8 May 2013 at 4:35 AM, Hanmac (Hans Mackowiak) wrote:</p>
<blockquote>
<p>i am against that, what about methods that are defined in Kernel, but you want when you are inside an BasicObject?<br>
you need something like:<br>
Kernel::Array([])<br>
or<br>
Kernel.Array([])<br>
what does make more sense for you?</p>
</blockquote>
<p>I actually prefer the '::Kernel.Array' example here (although I can see both sides of the argument), just because it makes it perfectly obvious that 'Array' is actually a method call and not something else.</p>
<p>On Wednesday, 8 May 2013 at 6:03 AM, Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>This is a weird case due to the upper case first letter, what do you think about:<br>
::Kernel::puts "Hello"<br>
versus<br>
::Kernel.puts "Hello"</p>
</blockquote>
<p>I definitely think '::Kernel.puts' is better here.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391862013-05-08T08:56:10Zhenry.maddocks (Henry Maddocks)hmaddocks@me.com
<ul></ul><p>charliesome (Charlie Somerville) wrote:</p>
<blockquote>
<p>(({::})) is usually a constant lookup operator, but it can also be used to call methods.</p>
</blockquote>
<p>Is it? I thought it was the scope resolution operator.</p>
<p>charliesome (Charlie Somerville) wrote:</p>
<blockquote>
<p>This can confusing to people learning Ruby.</p>
</blockquote>
<p>It depends what language you're coming from.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391872013-05-08T09:57:19ZAnonymous
<ul></ul><p>+1</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391882013-05-08T11:55:32Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>=begin<br>
henry.maddocks (Henry Maddocks) wrote:</p>
<blockquote>
<p>charliesome (Charlie Somerville) wrote:</p>
<blockquote>
<p>(({::})) is usually a constant lookup operator, but it can also be<br>
used to call methods.</p>
</blockquote>
<p>Is it? I thought it was the scope resolution operator.</p>
</blockquote>
<p>While I know better, my gut instinct is always to agree; and that, by contrast, (({.})) is for the receiver of a method. For example:</p>
<p> <br>
::Kernel::Array(3)<br>
#=> in global namespace,</p>
<a name="in-nested-namespace-Kernel"></a>
<h1 >in nested namespace 'Kernel',<a href="#in-nested-namespace-Kernel" class="wiki-anchor">¶</a></h1>
<a name="invoke-method-Array-with-no-receiver"></a>
<h1 >invoke method 'Array' with no receiver<a href="#invoke-method-Array-with-no-receiver" class="wiki-anchor">¶</a></h1>
<a name="perlish-KernelArray3"></a>
<h1 >perlish: @::Kernel::Array(3)<a href="#perlish-KernelArray3" class="wiki-anchor">¶</a></h1>
<p>::Kernel.Array(3)<br>
#=> in global namespace,</p>
<a name="in-nested-namespace-Kernel-2"></a>
<h1 >in nested namespace 'Kernel',<a href="#in-nested-namespace-Kernel-2" class="wiki-anchor">¶</a></h1>
<a name="invoke-method-Array-with-Kernel-as-receiver"></a>
<h1 >invoke method 'Array' with 'Kernel' as receiver<a href="#invoke-method-Array-with-Kernel-as-receiver" class="wiki-anchor">¶</a></h1>
<a name="perlish-Kernel-gtArray3-or-KernelArrayKernel3"></a>
<h1 >perlish: @::Kernel->Array(3), or @::Kernel::Array(::Kernel,3)<a href="#perlish-Kernel-gtArray3-or-KernelArrayKernel3" class="wiki-anchor">¶</a></h1>
<p>However I know that's not the case; and in fact (({::})) means different things if the right-hand parameter thingy is a constant or function. I.e. (({obj.foo})) ~ (({obj::foo()})) ~ (({obj::foo})), but (({obj.FOO})) ~ (({obj::FOO()})) ≁ (({obj::FOO})), irrespective of ((|obj|)) being a Class or not.</p>
<p>The whole thing would be made much more clear if (({::FOO()})) and (({::foo})) were removed, and (({::})) was always only used to resolve constants.</p>
<blockquote>
<p>charliesome (Charlie Somerville) wrote:</p>
<blockquote>
<p>This can confusing to people learning Ruby.</p>
</blockquote>
<p>It depends what language you're coming from.</p>
</blockquote>
<p>Unless you're coming from Ruby, I'm pretty sure it's confusing for everyone.</p>
<p>=end</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=391952013-05-08T18:23:11Zyorickpeterse (Yorick Peterse)yorickpeterse@gmail.com
<ul></ul><p>I'm in favour of deprecating <code>::</code> for method calls as well. I'm all for<br>
"multiple roads to Rome" but when it comes to the method calling syntax<br>
I really want it to be consistent.</p>
<p>Actually getting rid of the operator is going to be interesting though<br>
since I believe it's used in various places of MRI's core/std library as<br>
well as third-party projects. This is probably something that shouldn't<br>
be removed until at least 2.2.</p>
<p>Yorick</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392032013-05-08T23:42:29Zdgutov (Dmitry Gutov)dgutov@yandex.ru
<ul></ul><p>+1</p>
<p>"::" method call syntax has no advantages over ".", and it should be relatively simple to search through any codebase and convert the instances of using the former into the latter automatically.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392092013-05-09T04:13:09Zbozhidar (Bozhidar Batsov)bozhidar@batsov.com
<ul></ul><p>+1</p>
<p>Apart from having no advantages over ".", "::" for method calls is very rarely used even anyways. It has been effectively deprecated by the Ruby community and it now has to be deprecated by Ruby itself :-)</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392102013-05-09T04:13:15Zrubiii (Daniel Harrington)me@rubiii.com
<ul></ul><p>I'm also very much in favour of this change for simplicity.</p>
<p>When I learned about Nokogiri, I had no idea how this was supposed to work: Nokogiri::XML('')<br>
Simply changing the code to use a '.' instead of '::' makes it clear, that we're sending the '.XML' message.<br>
So why not encourage people to write code that is easier to read?!</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392152013-05-09T17:35:02Zhenry.maddocks (Henry Maddocks)hmaddocks@me.com
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>=begin<br>
henry.maddocks (Henry Maddocks) wrote:</p>
<blockquote>
<p>charliesome (Charlie Somerville) wrote:<br>
It depends what language you're coming from.</p>
</blockquote>
<p>Unless you're coming from Ruby, I'm pretty sure it's confusing for everyone.</p>
<p>=end</p>
</blockquote>
<p>C++ and PHP also use the scope resolution operator.</p>
<p>As for the rest of what you said, I don't understand.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392162013-05-09T17:54:43Zhenry.maddocks (Henry Maddocks)hmaddocks@me.com
<ul></ul><p>rubiii (Daniel Harrington) wrote:</p>
<blockquote>
<p>I'm also very much in favour of this change for simplicity.</p>
<p>When I learned about Nokogiri, I had no idea how this was supposed to work: Nokogiri::XML('')<br>
Simply changing the code to use a '.' instead of '::' makes it clear, that we're sending the '.XML' message.<br>
So why not encourage people to write code that is easier to read?!</p>
</blockquote>
<p>But '.' and '::' mean different things.<br>
'::' means you are calling the method that is defined inside the Nokogiri module/namespace. Changing it to use a dot means that you are sending a message to the object Nokogiri.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392172013-05-09T17:59:12Zyorickpeterse (Yorick Peterse)yorickpeterse@gmail.com
<ul></ul><p>Although in PHP you can also abuse the <code>::</code> for both static and non<br>
static method calls it's actually not used for namespaces (unlike Ruby),<br>
instead it uses backslashes for that. Although this means that there's<br>
still two ways to call a method (syntax wise) you at least don't end up<br>
using a syntax feature meant for something completely unrelated to<br>
method calls.</p>
<p>PHP is also a terrible language so I don't think it's worth comparing to<br>
at all.</p>
<p>Yorick</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392192013-05-09T18:52:33ZAnonymous
<ul></ul><p>henry.maddocks (Henry Maddocks) wrote:</p>
<blockquote>
<p>But '.' and '::' mean different things.<br>
'::' means you are calling the method that is defined inside the Nokogiri module/namespace. Changing it to use a dot means that you are sending a message to the object Nokogiri.</p>
</blockquote>
<p>This isn't correct. Nokogiri.XML() and Nokogiri::XML() are equivalent.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392212013-05-09T22:13:04Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><ul>
<li>we haven't reached consensus to remove double colons for method calls from the language.</li>
<li>even if we do, 2.2 is not the right time to remove, maybe 3.0.</li>
<li>we have convention of Array class and Array(obj) conversion method, why not Foo::Bar and Foo::Bar(obj)?</li>
</ul>
<p>Matz.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392242013-05-09T23:11:41Zdgutov (Dmitry Gutov)dgutov@yandex.ru
<ul></ul><blockquote>
<p>we haven't reached consensus to remove double colons for method calls from the language.</p>
</blockquote>
<p>That's what this issue is about, isn't it?</p>
<blockquote>
<p>even if we do, 2.2 is not the right time to remove, maybe 3.0.</p>
</blockquote>
<p>I agree. But deprecating it would already be beneficial.</p>
<blockquote>
<p>we have convention of Array class and Array(obj) conversion method, why not Foo::Bar and Foo::Bar(obj)?</p>
</blockquote>
<p>Foo.Bar(obj) is much better. Writing it another way makes it confusing for a human reader, like it's somehow a special, callable class.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392292013-05-10T00:50:51Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>More cases of ambiguity:</p>
<p>obj::FOO is always a constant lookup. obj::FOO() is always a method call.</p>
<p>obj::foo is always a method call. There's no way to omit parens for a :: call if the method name is capitalized.</p>
<p>I support removal as well. It doesn't add anything and it confuses more often than not.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392302013-05-10T01:22:43Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>headius (Charles Nutter) wrote:</p>
<blockquote>
<p>More cases of ambiguity:</p>
<p>obj::FOO is always a constant lookup. obj::FOO() is always a method call.</p>
<p>obj::foo is always a method call. There's no way to omit parens for a :: call if the method name is capitalized.</p>
</blockquote>
<p><code>obj::FOO 1</code> is a method call. You don't even need parens for a capitalized method that takes no arguments if you get creative: <code>obj::FOO *[]</code> :)</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392322013-05-10T01:33:06Zalexeymuranov (Alexey Muranov)
<ul></ul><p>This is related and has not yet been rejected: <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: Support functional programming: forbid instance/class variables for ModuleName::method_name, allo... (Feedback)" href="https://redmine.ruby-lang.org/issues/6806">#6806</a></p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392522013-05-12T00:12:05Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p>=begin<br>
I'm not sure how I feel about this. I understand the potential for confusion, but at the same time there's a certain congruity of being able to inherit from classes or methods that create classes in the same way. For example:</p>
<pre><code>module Foo
class Bar
def say
"Hello from Bar!"
end
end
def self.Bar(greeting)
klass = Class.new
klass.class_eval <<-END
def say
"#{greeting} from parameterized Bar!"
end
END
klass
end
end
class Baz < Foo::Bar
def shout
say.upcase
end
end
class Quux < Foo::Bar("Howdy")
def shout
say.upcase
end
end
puts Baz.new.shout
puts Quux.new.shout
</code></pre>
<p>If we remove the ability to call methods with (({::})), then the class definition lines don't match as nicely:</p>
<pre><code>class Baz < Foo::Bar
...
class Quux < Foo.Bar("Howdy")
...
</code></pre>
<p>Though I'd be interested to hear Mr. Evans opinion, since I think Sequel is where I've seen this used to the greatest effect...<br>
=end</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=392532013-05-12T02:11:37Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>jballanc (Joshua Ballanco) wrote:</p>
<blockquote>
<p>If we remove the ability to call methods with (({::})), then the class definition lines don't match as nicely:</p>
<pre><code>class Baz < Foo::Bar
...
class Quux < Foo.Bar("Howdy")
...
</code></pre>
<p>Though I'd be interested to hear Mr. Evans opinion, since I think Sequel is where I've seen this used to the greatest effect...</p>
</blockquote>
<p>I'm against removing it, since I think there are places where the syntax looks nicer with :: (constructors such as Sequel::Model() and Nokogiri::XML()). Having only one way to do something for its own sake is not the ruby way, and I think the loss of backwards compatibility and nicer syntax outweighs the reduced confusion. I don't train new ruby programmers, though, so maybe I underestimate the confusion this causes.</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=393122013-05-14T04:23:22Zjudofyr (Magnus Holm)judofyr@gmail.com
<ul></ul><p>On Sat, May 11, 2013 at 7:11 PM, jeremyevans0 (Jeremy Evans) <<br>
<a href="mailto:merch-redmine@jeremyevans.net" class="email">merch-redmine@jeremyevans.net</a>> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Deprecate :: for method calls in 2.1 (Rejected)" href="https://redmine.ruby-lang.org/issues/8377">#8377</a> has been updated by jeremyevans0 (Jeremy Evans).</p>
<p>jballanc (Joshua Ballanco) wrote:</p>
<blockquote>
<p>If we remove the ability to call methods with (({::})), then the class<br>
definition lines don't match as nicely:</p>
<pre><code>class Baz < Foo::Bar
...
class Quux < Foo.Bar("Howdy")
...
</code></pre>
<p>Though I'd be interested to hear Mr. Evans opinion, since I think Sequel<br>
is where I've seen this used to the greatest effect...</p>
</blockquote>
<p>I'm against removing it, since I think there are places where the syntax<br>
looks nicer with :: (constructors such as Sequel::Model() and<br>
Nokogiri::XML()). Having only one way to do something for its own sake is<br>
not the ruby way, and I think the loss of backwards compatibility and nicer<br>
syntax outweighs the reduced confusion. I don't train new ruby<br>
programmers, though, so maybe I underestimate the confusion this causes.</p>
</blockquote>
<p>Can't you use use #[] for this?</p>
<p>class Quuz < Foo::Bar["Howdy"]<br>
end</p>
<p>class User < Sequel::Model[:User]<br>
end</p>
<p>doc = Nokogiri::XML[data]</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=393142013-05-14T07:24:50Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul></ul><p>On 05/14 04:01, Magnus Holm wrote:</p>
<blockquote>
<p>On Sat, May 11, 2013 at 7:11 PM, jeremyevans0 (Jeremy Evans) <</p>
<blockquote>
<p>I'm against removing it, since I think there are places where the syntax<br>
looks nicer with :: (constructors such as Sequel::Model() and<br>
Nokogiri::XML()). Having only one way to do something for its own sake is<br>
not the ruby way, and I think the loss of backwards compatibility and nicer<br>
syntax outweighs the reduced confusion. I don't train new ruby<br>
programmers, though, so maybe I underestimate the confusion this causes.</p>
</blockquote>
<p>Can't you use use #[] for this?</p>
<p>class Quuz < Foo::Bar["Howdy"]<br>
end</p>
<p>class User < Sequel::Model[:User]<br>
end</p>
<p>doc = Nokogiri::XML[data]</p>
</blockquote>
<p>In the case of Sequel::Model, no, since Sequel::Model.[] is already<br>
defined and does something different than creating a subclass.</p>
<p>Usage of [] for constructors seems fairly uncommon (Hash.[] is the<br>
exception that comes to mind), so from a syntax level it is more likely<br>
to be confusing. Using capitalized methods for constructors is much<br>
more common in ruby (e.g. Kernel::{String,Array,Integer,Float,...}).</p>
<p>Jeremy</p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=396342013-06-02T16:12:44Zzzak (zzak _)
<ul><li><strong>Target version</strong> changed from <i>2.1.0</i> to <i>3.0</i></li></ul><p>See <a href="/issues/8377">[ruby-core:54883]</a></p> Ruby master - Feature #8377: Deprecate :: for method calls in 2.1https://redmine.ruby-lang.org/issues/8377?journal_id=410812013-08-11T13:46:23Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>Hi,</p>
<p>Matz rejected this here:</p>
<p><a href="https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20130809#Deprecate-for-method-calls-8377" class="external">https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20130809#Deprecate-for-method-calls-8377</a></p>
<p>So I'm closing this. :-)</p>