So you would say use :: only for constant access, and use '.' for
method access be it in a class or module?
Certainly, IMO. I usually say Math.sin rather than Math::sin. Basically
I don't care in general whether it's a class or just a module. (There
might be times when I do care.)
As for module names and class names (replying to what someone else said),
remember that these are typically constants. In other words, if Foo::Bar
is a class, it's just a special case of Foo::Bar being a constant.
So you would say use :: only for constant access, and use '.' for
method access be it in a class or module?
Well class-methods are constant as well in a sense, hence the use of
"::" in Why's book and it being the (at least old-school) idiom,
I disagree; I don't think class methods are constant in any sense, any
more than any other method definition. They're basically just
per-object/singleton method definitions:
class C
def C.x
end
end
like
str = "abc"
def str.x
end
etc. They have a semi-special status in the language (e.g., the
existence of the #class_methods method), but when you call one, you're
just sending a message to an object for method-call-based response.
That's different from retrieving a constant, but it's not different
from calling a method on any other object.
> Well class-methods are constant as well in a sense, hence the use of
> "::" in Why's book and it being the (at least old-school) idiom,
I disagree; I don't think class methods are constant in any sense, any
more than any other method definition. They're basically just
per-object/singleton method definitions:
True. Still, there's a subtle difference. I agree, however, that
there's really no good reason to use "::" in this case; I certainly
write
File.open ...
rather than
File::open ...
which is one symbol longer and doesn't make it easier to read,
nikolai
···
--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
I, however, am very familiar with C++, and I also cannot experience the
pleasure of being reminded of its style.
···
On Tuesday 15 February 2005 08:25 pm, David A. Black wrote:
On Wed, 16 Feb 2005, Yukihiro Matsumoto wrote:
> I allow '::' for method calls to denote class methods (with C++ style
> appearance). David doesn't like it. I think _why liked it.
I never learned C++, so I can't experience the pleasure of being
reminded of its style
--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
I allow '::' for method calls to denote class methods (with C++ style
appearance). David doesn't like it. I think _why liked it.
I like it okay. Not with fervor.
@var is instance var. obj.meth is instance method.
@@var is class var. obj::meth is class method.
I guess I thought that the notion of single-character for any instance syntax and double-character for any class syntax might be simpler.
With such cases (I apply the same rule to constant naming, I don't see why I should use SHOUTING_CAPS for non-class constants) I always wonder about others doing an arbitrary distinction between classes and objects -- are classes after all not also objects?