From: dblack@... Date: 2006-03-27T01:17:10+09:00 Subject: Re: Noob: use of the double colon Hi -- On Mon, 27 Mar 2006, ara.t.howard@noaa.gov wrote: > On Sun, 26 Mar 2006 dblack@wobblini.net wrote: > >>> Bothe seem to work OK. >>> Is there a difference? If yes, what is the difference? >> >> They do both work. I've never understood why the :: exists for this >> purpose, since the . is the normal way of sending messages to objects >> and works perfectly well whether or not the receiver is a class. It's >> on my very short list of things I'd like to see removed from Ruby. > > i think it's quite useful in the context of metaprogramming or classes or > modules as variables: > > m = method_returning_an_module > m::module_method > > c = method_returning_an_class > c::class_method > > o = method_returning_an_object > o.object_method > > i find this approach helps me understand which kind of thing my variables > have > at a quick glance. it's a similar idea to naming arrays with plural words > > people = [] > person = people.first > > which some hate and some love. Does anyone hate calling a variable person? :-) > still, these kinds of techniques can reduce the need for comments > and preserve programmer sanity. I honestly don't see any connection between the two techniques (:: and suggestive variable names). c::meth doesn't communicate anything to me about c. Even if it did, I'm not sold on the idea that it's necessary to have a different message-sending operator for a particular class of objects. It doesn't scale: you can come up with lots of variable names (my_class, etc.), but you can't keep adding operators to make distinctions among receivers. Nor is it necessarily vital in very many cases to make such distinctions. And when it's a matter of String.new vs. String::new, you already know it's a class anyway :-) David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black