Hello. Today, we will learn about variables
and the types available in Pharo.
In fact, there are two big types:
local variables always start with lowercase by convention;
we will see the local types available.
The second big group is shared variables.
They start with uppercase by convention.
There are also several types.
Let's start with local variables which start with lowercase.
Local variables have one method.
They are declared between pipes,
the vertical bars.
Here, there's a local variable, c:
it's local to the method and exists only for its execution.
Therefore, it must always start with lowercase.
By the way, all the class names start with uppercase
because they are shared in the system.
Other types of local variables:
for example, there are instance variables in the object
which are local to it. There are two of them here: x and y.
They always start with lowercase.
As for local variables,
there are also the methods' arguments, here.
In aPoint, "a" is lowercase.
because this variable is also local to the method.
There are also block parameters.
For :x, x is a local variable to a block.
A block argument, sorry.
So here, it starts with lowercase.
In Pharo, there are six specific variables,
called special variables; you can't change their names.
They are reserved words in Pharo.
There are more than 50 of them in Java or JavaScript;
in Pharo, only six.
These are true, false, nil, self, super, and thisContext.
Let's figure out what these reserved words are for.
true and false are instances of Booleans:
true is the unique instance of the class True;
false, the unique instance of the class False.
nil is the unique instance of the class UndefinedObject.
So true, false, and nil are objects like any other,
except they are the unique instances of a specific class in the system.
Next, there are three pseudo-variables:
self refers to the current receiver, and it's equivalent to this in Java.
super always refers to the current receiver,
but this time, when you send a message via super,
it means the method lookup, the selection method algorithm,
which we will see in another class,
will start in the superclass where the keyword super is written.
thisContext is a pseudo-variable which refers to the object
that reifies the program's call stack.
It's an advanced concept we'll study at the end of this MOOC.
We will explain it to you later.
For now, you just need to know it's a pseudo-variable.
Now, shared or global variables.
First, you have all the classes.
All class names start with uppercase
because I can reference a class from anywhere in the system.
Be careful: what starts with uppercase is not always a class.
For example, Transcript:
it's an object name shared in the system.
Everyone can reference this object.
And it's standard output, stdout in other languages.
It's an instance object of a class, globally accessible.
So its name starts with uppercase.
There are also class variables,
which are declared here when declaring a class in classVariableNames;
here, the class #CombinedChar defines two class variables,
one called Compositions and the other Decompositions.
These two class variables
are accessible by the instances of the class #CombinedChar
and of its subclasses.
That's why they're called shared variables.
All the instances of the class and its subclasses share them.
So both of them start with uppercase.
To summarize, you must remember:
all local variables, local to an object, a block, or a method,
start with lowercase;
all global variables, such as class names, etc.,
start with uppercase.