Ruby, Smalltalk and Class Variables(patshaughnessy.net)
patshaughnessy.net
Ruby, Smalltalk and Class Variables
http://patshaughnessy.net/2012/12/17/ruby-smalltalk-and-class-variables
6 comments
Thanks Gary... yea and all of these things more or less mean the same thing.
At a more technical, detailed level, however, the Ruby core team uses both the term "metaclass" (in the same sense Smalltalk uses it - the class of a class), and the term "singleton" (the hidden class of a single object instance). You can see what I mean by looking through the MRI class.c source file.
At a more technical, detailed level, however, the Ruby core team uses both the term "metaclass" (in the same sense Smalltalk uses it - the class of a class), and the term "singleton" (the hidden class of a single object instance). You can see what I mean by looking through the MRI class.c source file.
This is one of the areas that prototype-based languages simplifies although access issues might trouble class lovers. I do miss NewtonScript for some things.
Example: I create an object called Polygon with the intent to use it as a prototype. I assign the variable sides with a value of 10. So, anything with a parent pointer of Polygon gets 10. I then create Triangle from Polygon and assign sides = 3. It doesn't affect Polygon (which has its own variable), but anything that has a parent pointer of Triangles get the 3.
Example: I create an object called Polygon with the intent to use it as a prototype. I assign the variable sides with a value of 10. So, anything with a parent pointer of Polygon gets 10. I then create Triangle from Polygon and assign sides = 3. It doesn't affect Polygon (which has its own variable), but anything that has a parent pointer of Triangles get the 3.
Io (http://iolanguage.org/) shares the same differential inheritance has NewtonScript:
Polygon := Object clone do( sides := 10 )
Triangle := Polygon clone
Triangle sides println # => 10
Triangle sides := 3
Triangle sides println # => 3
Polygon sides println # => 10Making that simple is not necessarily limited to prototype-based languages. Another (as good as) dead language of Apple's design, Dylan, is class-based, but has a 'each-subclass' modifier that makes a slot magically appear new in each subclass. You would have to design your polygon class for that, though; it is not something that triangle could magically add.
It is too bad someone hasn't gone back a released a retooled, s-expr version of Dylan. It was an interesting language. People should read the manual (infix) just to see how they did macros.
I'd never read the linked Alan Kay paper about the development of Smalltalk [1]. It's fascinating!
I've been trying for awhile to find readings or videos (or anything, really) about those early days at ARPA and then PARC. Especially the detailed discussion of the smalltalk development. The names and stories are also pretty neat to read, and have already inspired a few ideas personally.
[1] http://www.smalltalk.org/smalltalk/TheEarlyHistoryOfSmalltal...
I've been trying for awhile to find readings or videos (or anything, really) about those early days at ARPA and then PARC. Especially the detailed discussion of the smalltalk development. The names and stories are also pretty neat to read, and have already inspired a few ideas personally.
[1] http://www.smalltalk.org/smalltalk/TheEarlyHistoryOfSmalltal...
I agree - it's an amazing narrative of an interesting time. I wonder if contacting Xerox directly would lead to some more historical archives?
This was also discussed five years ago in this great post by Martin Fowler: http://martinfowler.com/bliki/ClassInstanceVariable.html
Yea it's been a source of discussion (and confusion) for years. Thanks for the link!
In the Perl/Moose world, class variables (attributes) are regarded as a broken concept: http://www.perlmonks.org/?node_id=690482
ref: stvn == "Stevan Little" who is the creator of Moose (https://metacpan.org/module/Moose) & and it's MOP underpinnings (https://metacpan.org/module/Class::MOP)
ref: stvn == "Stevan Little" who is the creator of Moose (https://metacpan.org/module/Moose) & and it's MOP underpinnings (https://metacpan.org/module/Class::MOP)
In Kay's Smalltalk, humans never saw code like that in the article: they defined classes, variables and methods through a graphical interface. The verbose syntax was for computers to read, when you saved code on one machine and loaded it on another. Humans only had to write this stuff after Gnu released a text-only interpreter; the subset of Smalltalk syntax that was originally intended for human use is pretty clear.
For quite a while there was little agreement on this name because there was no standard method that could be called to return the singleton class and therefore no agreed upon name. The only access was via syntax:
The results of this expression were called metaclass, eigenclass, singleton class, and probably a few more names.
There is now a standard method:
and so, for the most part, the naming confusion is fading away.