Pharo and instance variables ...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Pharo and instance variables ...

James Ladd
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Dave Mason
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html


Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Dave Mason
In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html




Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
Ah that is very helpful - thank you.

addFirst: newObject 
"Add newObject to the beginning of the receiver. Answer newObject."

firstIndex = 1 ifTrue: [self makeRoomAtFirst].
firstIndex := firstIndex - 1.
array at: firstIndex put: newObject.
^ newObject



On Wed, Oct 18, 2017 at 2:41 PM, David Mason <[hidden email]> wrote:
In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html





Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
In reply to this post by Dave Mason
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html




Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Clément Béra


On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq
Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
What if accessors were generated but not mutators?

Sent from my Commodore 64

On 18 Oct 2017, at 4:21 pm, Clément Bera <[hidden email]> wrote:



On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq
Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Markus Stumptner

It would break code all over the place...


On 18/10/2017 16:02, James Ladd wrote:
What if accessors were generated but not mutators?

Sent from my Commodore 64

On 18 Oct 2017, at 4:21 pm, Clément Bera <[hidden email]> wrote:



On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq

Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Prof. Andrew P. Black
In reply to this post by James Ladd

On 18 Oct 2017, at 08:32 , James Ladd <[hidden email]> wrote:

What if accessors were generated but not mutators?


The point is that, once a method exists, there is not way to restrict who can send a message that will execute it.  So if one were forces to generate a reader method, or a writer method, just to give access to a subclass, then every object n the system would also gain access.

Andrew


Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
In reply to this post by Markus Stumptner
Good point thanks 

Sent from my Commodore 64

On 18 Oct 2017, at 4:34 pm, Markus Stumptner <[hidden email]> wrote:

It would break code all over the place...


On 18/10/2017 16:02, James Ladd wrote:
What if accessors were generated but not mutators?

Sent from my Commodore 64

On 18 Oct 2017, at 4:21 pm, Clément Bera <[hidden email]> wrote:



On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq

Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
In reply to this post by Prof. Andrew P. Black
Good point - thank you 

Sent from my Commodore 64

On 18 Oct 2017, at 4:36 pm, Prof. Andrew P. Black <[hidden email]> wrote:


On 18 Oct 2017, at 08:32 , James Ladd <[hidden email]> wrote:

What if accessors were generated but not mutators?


The point is that, once a method exists, there is not way to restrict who can send a message that will execute it.  So if one were forces to generate a reader method, or a writer method, just to give access to a subclass, then every object n the system would also gain access.

Andrew


Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

kilon.alios
In reply to this post by Prof. Andrew P. Black
Well the method of the receiver can check for the type of the object from which you receive a message, technically you can restrict the access even to a particular instance object. You can enforce a ton of restrictions as the entire system is modifiable and live. 

On Wed, Oct 18, 2017 at 8:37 AM Prof. Andrew P. Black <[hidden email]> wrote:

On 18 Oct 2017, at 08:32 , James Ladd <[hidden email]> wrote:

What if accessors were generated but not mutators?


The point is that, once a method exists, there is not way to restrict who can send a message that will execute it.  So if one were forces to generate a reader method, or a writer method, just to give access to a subclass, then every object n the system would also gain access.

Andrew


Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

James Ladd
In reply to this post by Markus Stumptner
That said from memory I think it was Digitalk or Enfin that used to automatically generate accessors and mutators 

Sent from my Commodore 64

On 18 Oct 2017, at 4:34 pm, Markus Stumptner <[hidden email]> wrote:

It would break code all over the place...


On 18/10/2017 16:02, James Ladd wrote:
What if accessors were generated but not mutators?

Sent from my Commodore 64

On 18 Oct 2017, at 4:21 pm, Clément Bera <[hidden email]> wrote:



On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq

Reply | Threaded
Open this post in threaded view
|

Re: Pharo and instance variables ...

Ben Coman
Hi James,

As an offshoot to your question, when I wanted to understand the difference 
between "instance variables", "class variables" and "class instance variables"
I made this quick demo...
that could make a good test to compare to existing Smalltalk systems.

cheers -ben

On Wed, Oct 18, 2017 at 6:45 PM, James Ladd <[hidden email]> wrote:
That said from memory I think it was Digitalk or Enfin that used to automatically generate accessors and mutators 

Sent from my Commodore 64

On 18 Oct 2017, at 4:34 pm, Markus Stumptner <[hidden email]> wrote:

It would break code all over the place...


On 18/10/2017 16:02, James Ladd wrote:
What if accessors were generated but not mutators?

Sent from my Commodore 64

On 18 Oct 2017, at 4:21 pm, Clément Bera <[hidden email]> wrote:



On Wed, Oct 18, 2017 at 7:07 AM, James Ladd <[hidden email]> wrote:
Hey David,

If you could only access instance variables in the class that defined them and therefore only in a subclass via an accessor / mutator method w that be a big problem in your view?

Yes.

I don't want to have to define accessors, which are public, just to have the subclasses access the instance variables.
 

Sent from my Commodore 64

On 18 Oct 2017, at 2:41 pm, David Mason <[hidden email]> wrote:

In Pharo, open a browser on OrderedCollection, then click "Variables" in the top left of the window and then "array"... if you scroll through you can see that mostly OrderedCollection methods use it, but some SortedCollection (a subclass) methods also use it.

The model is similar to protected in Java (see http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html ) except there is no "Package" column.

On 17 October 2017 at 23:30, James Ladd <[hidden email]> wrote:
Please could you provide an example?



On Wed, Oct 18, 2017 at 2:16 PM, David Mason <[hidden email]> wrote:
Any instance method in the class where the instance variable is defined or in a subclass can access the instance variable.  Similarly for class methods to access class-side variables, and for class and instance methods to access class variables.

On 17 October 2017 at 23:04, James Ladd <[hidden email]> wrote:
Hello Pharo Users,

I'm wondering about instance variables for support in Redline Smalltalk and
want to get my understanding straight.

Are instance variables only accessible (without using #instVarNamed:) inside
the method with the same name as the instance variable?

eg:

   myInstVar
   ^ myInstVar.

Or can you reference an instance variable from a method that doesn't have
the same name ?

   anotherMethod
   ^ myInstVar.

Can someone give me or point me to an example of accessing an instance
variable in Pharo Smalltalk?

- James.




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







--
Clément Béra
Pharo consortium engineer
Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq