[I meant to post this to clr in the first place... it may show up
twice on ruby-talk]

Hi --

On Sat, 29 May 2004, Sean O'Dell wrote:

> On Friday 28 May 2004 11:56, Austin Ziegler wrote:
> > >>S> There really should be a module called global, or
> > >>S> perhaps an object named global, that keeps all the global
> > >>S> variables and methods. That way you could just call
> > >>S> global.method. There should also be syntax sugar to allow you
> > >>S> to say ::method.
> > >> "global" methods are private : this is why you can't call
> > >> Object.test
> > >>
> > >> svg% ruby -e 'def test() end; p Object.test'
> > >> -e:1: private method `test' called for Object:Class (NoMethodError)
> > >> svg%
> > >
> > > Yes, but that's not how globals usually behave. Globals are
> > > usually always globally available unless overridden or removed.
> >
> > Does Ruby *need* globals, especially given that Kernel already
> > exists?
> 
> Kernel is just another way of saying global.  How you implement globals 
> doesn't change the concept of globals itself.  Whether they're held in a 
> nameless or named space, they're still globals.

Yes, but *whether* you implement globals does change the question of
whether you should be judged, as a language, on the cleanness of your
implementation of globals :-)  You're assuming that Ruby is somehow
accountable for implementing globals, and then (not surprisingly)
finding that it does so inadequately.  But there's no reason to hold
Ruby to that contract in the first place.  

> But it seems to me that Kernel ended up being the global namespace
> after a couple paradigm changes, and there isn't much consistency
> about them.  Some globals are private members of Object and some are
> in Kernel.  You can access global variables anywhere using $, but
> you can't access all global methods from anywhere.  You can access
> Kernel::method globals, if they're in Kernel, but if they're a
> private member of Object, you have to perform some strange tricks.

No stranger than with other private methods.  The only singularity, I
think, is the fact that methods written at the top-level are given
this status in the first place (and they had to go *somewhere* :-)
Beyond that, everything grows very organically out of the basic
premises of Ruby.  For example, this:

  class Object
    private
    def x; end
  end

(or just "def x; end" at the top level, with the wrapper implicit) is
very similar to this:

  class C
    private
    def y; end
  end

with respect to what you have to do later to get at the method.  

Similarly, Kernel -- though obviously a very important module -- is
just part of the module and mixin mechanism of Ruby, and behaves
accordingly.

What results from all of this may look somewhat like global-ness, but
it isn't, nor does it claim to be.  It's just Ruby being Ruby.  


David

-- 
David A. Black
dblack / wobblini.net