Variables

Damien Cassou, St├ęphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

In a Nutshell

Local Variables Start With Lowercase

Temporary variables are local to the method

Example: c

CounterTest >> testIncrement
   | c |
   c := Counter new.
   ...

Remember: class names start with uppercase

Local Variables Start With Lowercase

Instance variables are local to the object

Example: x, y, count

Object subclass: #Point
   instanceVarNames: 'x y'
Object subclass: #Counter
   instanceVarNames: 'count'

Local Variables Start With Lowercase

Method arguments: aPoint

crossProduct: aPoint 
  "Answer a number that is the cross product of the receiver and the 
  argument, aPoint."

  ^ (x * aPoint y) - (y * aPoint x)

Block arguments: :x

[ :x | x + 2 ]

Special Variables

Special variables cannot be changed

Special Variables

Special Variables

Shared or Global Variable starts with Uppercase

Object is a class globally accessible

Object subclass: #Point

Transcript is an object that is globally accessible (a kind of stdout)

Transcript cr.
Transcript show: 'hello world'.
Transcript cr.

ClassVariables are Shared Variables

Object subclass: #CombinedChar
   instanceVariableNames: 'codes combined'
   classVariableNames: 'Compositions Decompositions Diacriticals'
   package: 'Kernel-BasicObjects'

Summary

/