Smalltalk language limitation ?
John M McIntosh
johnmci at smalltalkconsulting.com
Sun Dec 5 08:26:32 UTC 2004
On Dec 4, 2004, at 8:56 PM, Doug Way wrote:
>
> On Dec 4, 2004, at 11:21 PM, Aaron Gray wrote:
>> What about messages to instance variables ?
>
> Not sure what you mean here. If you can get to the instance variable,
> you can send a message to it. (It is true that you can't reference an
> object's instance variable directly unless you are "inside" that
> object. Smalltalk instance variables have the equivalent of
> "protected" access in C++/Java-speak.)
>
> - Doug
Well I'll actually point out that normally if you don't have an
accessor method for an instance variable the you shouldn't be able to
access that instance variable outside the class
But to preserve the sanity of folks who want to something clever we
provide a way you can cheat.
Object>>instVarAt: index
"Primitive. Answer a fixed variable in an object. The numbering of the
variables corresponds to the named instance variables. Fail if the
index
is not an Integer or is not the index of a fixed variable. Essential.
See
Object documentation whatIsAPrimitive."
<primitive: 73>
"Access beyond fixed variables."
^self basicAt: index - self class instSize
To poke at instance variables that you don't have access to.
The reason for doing this usually implies something very clever, say
serializling an object to be sent over the internet, or
printing the contents of an object on the error log. However, doing
this as part of any non-clever drab business program is as
you might guess a frowned upon activity...
Aaron I'll point out an instance variable is just a placeholder for any
smalltalk object, which could be a number, a Class, an Array, a drab
business object. There is
no type restrictions or naming conventions that dictate terms/rules.
Beyond the acceptable practices that Class variables start with upper
case, and rules for how
instance variables are named, methods named etc. Again these are all
styles the community uses, see "Smalltalk with Style" for the rules.
Smalltalk is very clever and
flexible, none of the restrictions you are use to in other languages.
Try this link for some free smalltalk books
http://www.iam.unibe.ch/~ducasse/FreeBooks.html
--
========================================================================
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
========================================================================
===
More information about the Squeak-dev
mailing list
|