Hi --

On Fri, 15 Apr 2005, Trans wrote:

> Mark Hubbart wrote:
>> I think meta-programming would suffer.
>>
>> # a Foo that is sort of like a Bar
>> class FooBar < Foo
>>   bar_methods = Bar.instance_methods - self.instance_methods
>>   bar_methods.each{ ... }
>> end
>>
>> FooBar.bar_methods => ?????
>>
>> It would be like penalizing people for using metaprogramming
> techniques :(
>
> Hmm... I would think that code would work just fine. I'm not suggesting
> that local vars be displaced, if that is what you mean, only that they
> overlap. So a class local var is a class method is a class local var.
> It is the same namespace afterall (i.e. self resoves to the same thing)
> so that's okay too.

But if you can access it non-locally, then it isn't a local variable:

   class C
     x = []
   end

   C.x << 1

at which point it's unclear to me what happens when you do:

   class C
     puts x   # is this [1], or undefined?
   end

Local variables have the advantage of being 'scratch-pad'-like.  You
don't have to worry about outside access, nor about using the same
variable name twice in different scopes at the same level.  If these
things are no longer the case, then the change is pretty deep.


David

-- 
David A. Black
dblack / wobblini.net