Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] Article: Seeing Metaclasses Clearly

Reply
Thread Tools

[ANN] Article: Seeing Metaclasses Clearly

 
 
why the lucky stiff
Guest
Posts: n/a
 
      04-18-2005
I've written a very nuts+bolts article on metaclasses (aka virtual
classes or metaobjects), since they still lurk under a shroud of fear
and enigma.

<http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>

I'm hoping this will help uncover the truth. If anything is unclear,
please report it. Shed a light.

Sharkin',

_why



 
Reply With Quote
 
 
 
 
Sascha Ebach
Guest
Posts: n/a
 
      04-18-2005
why the lucky stiff wrote:
> I've written a very nuts+bolts article on metaclasses (aka virtual
> classes or metaobjects), since they still lurk under a shroud of fear
> and enigma.
>
> <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
>
> I'm hoping this will help uncover the truth. If anything is unclear,
> please report it. Shed a light.


Very nice and thanks,

would you mind using a print stylesheet so the article can be nicely
printed out?

Sascha Ebach


 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      04-18-2005
Hi --

On Mon, 18 Apr 2005, why the lucky stiff wrote:

> I've written a very nuts+bolts article on metaclasses (aka virtual classes or
> metaobjects), since they still lurk under a shroud of fear and enigma.
>
> <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
>
> I'm hoping this will help uncover the truth. If anything is unclear, please
> report it. Shed a light.


For some reason the first 1/8 inch or so on the left are cut off on my
browser. I don't know whether it's a CSS thing or a browser thing
(Netscape 6). So "methods" comes out as "thods", etc.

The tutorial itself looks good, though the terminology in this area
continues to be a problem. My understanding is that the most general
term is "singleton class", and that "metaclass" is a special term for
singleton class of a Class object. (See Pickaxe, 2nd ed., p. 382.)
So, for example, I would rename your Object#metaclass method
#singleton_class, since it applies to all objects (as per RCR 231).

Then there's "virtual class", which I think is the weakest and least
useful term, certainly at a general level. The Matz paraphrase on
p.382 suggests that virtual-ness is more a matter of implementation
than anything language-level, which is good. I haven't checked, but
I'm hoping the > 1.8 error messages will cease to refer to "virtual"
classes (e.g., when you try to get at the singleton class of a
Fixnum).


David

--
David A. Black
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
Florian Groß
Guest
Posts: n/a
 
      04-18-2005
why the lucky stiff wrote:

> <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
>
> I'm hoping this will help uncover the truth. If anything is unclear,
> please report it. Shed a light.


Nice article, but I disagree in the point that @@vars are simpler than
class instance variables. Class instance variables have odd semantics in
the current Ruby which means that they will probably do some detail
different than you expect.

I've found that sticking to class instance variables (and thus keeping
things simple -- why do we need another type of variables again?) helps
in making code easier to understand.

Perhaps you should display both sides of this in the article.



 
Reply With Quote
 
Gavin Kistner
Guest
Posts: n/a
 
      04-18-2005
On Apr 18, 2005, at 6:33 AM, Florian Groß wrote:
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics
> in the current Ruby which means that they will probably do some detail
> different than you expect.


But you have to do:

class Foo
@var1 = []
@var2 = {}
class << self
attr_accessor :var1, :var2
end
end

to get reasonable access to those class instance variables inside an
instance method, and even then you have to do self.class.var1


Once you 'get it' it's not TERRIBLY difficult, but I would say that the
above is more than enough justification for calling @@foo simpler.
Simpler, but also confusing in the inherited-class cases. (So confusing
that I still don't fully grok what specifically occurs that makes @@foo
unusable, and when it occurs. I'm still grasping at the fringes of the
tablecloth.)




 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      04-18-2005

"Florian Groß" <(E-Mail Removed)> schrieb im Newsbeitrag
news:d4093s$dml$(E-Mail Removed)...
> why the lucky stiff wrote:
>
> > <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
> >
> > I'm hoping this will help uncover the truth. If anything is unclear,
> > please report it. Shed a light.

>
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics in
> the current Ruby which means that they will probably do some detail
> different than you expect.
>
> I've found that sticking to class instance variables (and thus keeping
> things simple -- why do we need another type of variables again?) helps
> in making code easier to understand.


+1

> Perhaps you should display both sides of this in the article.


Yeah, I missed that, too. In fact, the article seems to discourage class
instance variable usage...

Kind regards

robert

 
Reply With Quote
 
Karl von Laudermann
Guest
Posts: n/a
 
      04-18-2005
why the lucky stiff wrote:
> I've written a very nuts+bolts article on metaclasses (aka virtual
> classes or metaobjects), since they still lurk under a shroud of fear


> and enigma.
>
> <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
>
> I'm hoping this will help uncover the truth. If anything is unclear,


> please report it. Shed a light.


Noticed a small mistake; At one point, you refer to the at-sign (@) as
an ampersand. Other than that... the article went way over my head and
twisted my poor brain into knots. I think I'll need to re-read
chapter 24 of Pickaxe 2 immediately before reading this article.

 
Reply With Quote
 
why the lucky stiff
Guest
Posts: n/a
 
      04-18-2005
Florian Groß wrote:
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics in
> the current Ruby which means that they will probably do some detail
> different than you expect.


You're right. I'm oversimplifying this. I need to discuss the
metaclass/inheritance thing a bit more.

_why



 
Reply With Quote
 
Curt Hibbs
Guest
Posts: n/a
 
      04-18-2005
David A. Black wrote:
> Hi --
>
> On Mon, 18 Apr 2005, why the lucky stiff wrote:
>
>> I've written a very nuts+bolts article on metaclasses (aka virtual
>> classes or
>> metaobjects), since they still lurk under a shroud of fear and enigma.
>>
>> <http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html>
>>
>> I'm hoping this will help uncover the truth. If anything is unclear,
>> please
>> report it. Shed a light.

>
>
> For some reason the first 1/8 inch or so on the left are cut off on my
> browser. I don't know whether it's a CSS thing or a browser thing
> (Netscape 6). So "methods" comes out as "thods", etc.


Also, in Firefox 1.0 on Windows XP, when I try to print it, it only
prints the first page. If I use MS Internet Explorer, it prints just fine.

Curt


 
Reply With Quote
 
why the lucky stiff
Guest
Posts: n/a
 
      04-18-2005
David A. Black wrote:
> The tutorial itself looks good, though the terminology in this area
> continues to be a problem. My understanding is that the most general
> term is "singleton class", and that "metaclass" is a special term for
> singleton class of a Class object. (See Pickaxe, 2nd ed., p. 382.)
> So, for example, I would rename your Object#metaclass method
> #singleton_class, since it applies to all objects (as per RCR 231).


Sure, I'm aware that "virtual class" is the generic term, while Matz has
also used "singleton class" and "meta-object" to describe these classes
used in tandem with an RObject.

I only use the term "metaclass" because it is the term predominantly
used in the PickAxe II. While Dave does interchangibly use "virtual
class" and "singleton class", the only term he uses to generically refer
to the construct is "metaclass".

And I really need to be able to wrap these up in a single word, whilst
still jiving with the PickAxe.

_why




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Canon 350D clearly beats Nikon D50 at dpreview.com GTO Digital Photography 86 10-03-2005 12:33 AM
A clearly instansiated object (a WebForm control) isn't instansiat =?Utf-8?B?S3Jpc3RpYW4=?= ASP .Net 1 02-07-2005 01:08 PM
Megapixels clearly explained George Preddy Digital Photography 40 01-28-2004 12:01 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM



Advertisments