﻿WEBVTT

00:00:00.360 --> 00:00:03.120 align:middle
Hello. Today, we will learn
about variables

00:00:03.280 --> 00:00:05.640 align:middle
and the types available in Pharo.

00:00:05.800 --> 00:00:07.840 align:middle
In fact, there are two big types:

00:00:08.000 --> 00:00:13.280 align:middle
local variables always start
with lowercase by convention;

00:00:13.440 --> 00:00:15.920 align:middle
we will see the local types available.

00:00:16.080 --> 00:00:18.800 align:middle
The second big group
is shared variables.

00:00:18.960 --> 00:00:22.560 align:middle
They start with uppercase by convention.

00:00:22.720 --> 00:00:24.640 align:middle
There are also several types.

00:00:25.600 --> 00:00:29.120 align:middle
Let's start with local variables
which start with lowercase.

00:00:29.280 --> 00:00:31.360 align:middle
Local variables have one method.

00:00:31.520 --> 00:00:36.000 align:middle
They are declared between pipes,

00:00:36.160 --> 00:00:37.400 align:middle
the vertical bars.

00:00:37.560 --> 00:00:39.920 align:middle
Here, there's a local variable, c:

00:00:40.080 --> 00:00:43.760 align:middle
it's local to the method
and exists only for its execution.

00:00:43.920 --> 00:00:46.960 align:middle
Therefore, it must always
start with lowercase.

00:00:47.120 --> 00:00:51.840 align:middle
By the way, all the class names
start with uppercase

00:00:52.000 --> 00:00:55.120 align:middle
because they are shared in the system.

00:00:56.800 --> 00:00:59.640 align:middle
Other types of local variables:

00:00:59.800 --> 00:01:03.560 align:middle
for example, there are
instance variables in the object

00:01:03.720 --> 00:01:07.120 align:middle
which are local to it.
There are two of them here: x and y.

00:01:07.280 --> 00:01:09.640 align:middle
They always start with lowercase.

00:01:09.800 --> 00:01:11.880 align:middle
As for local variables,

00:01:12.040 --> 00:01:15.560 align:middle
there are also
the methods' arguments, here.

00:01:16.280 --> 00:01:19.760 align:middle
In aPoint, "a" is lowercase.

00:01:19.920 --> 00:01:22.840 align:middle
because this variable
is also local to the method.

00:01:23.000 --> 00:01:26.880 align:middle
There are also block parameters.

00:01:27.040 --> 00:01:31.880 align:middle
For :x, x is a local variable
to a block.

00:01:32.040 --> 00:01:34.320 align:middle
A block argument, sorry.

00:01:34.480 --> 00:01:37.280 align:middle
So here, it starts with lowercase.

00:01:39.160 --> 00:01:43.440 align:middle
In Pharo, there are
six specific variables,

00:01:43.600 --> 00:01:46.840 align:middle
called special variables;
you can't change their names.

00:01:47.000 --> 00:01:48.720 align:middle
They are reserved words in Pharo.

00:01:48.880 --> 00:01:52.640 align:middle
There are more than 50 of them
in Java or JavaScript;

00:01:52.800 --> 00:01:54.160 align:middle
in Pharo, only six.

00:01:54.320 --> 00:01:57.720 align:middle
These are true, false, nil, self, super,
and thisContext.

00:01:57.880 --> 00:02:01.640 align:middle
Let's figure out
what these reserved words are for.

00:02:01.800 --> 00:02:04.360 align:middle
true and false
are instances of Booleans:

00:02:04.520 --> 00:02:07.240 align:middle
true is the unique instance
of the class True;

00:02:07.400 --> 00:02:10.160 align:middle
false, the unique instance
of the class False.

00:02:10.320 --> 00:02:13.760 align:middle
nil is the unique instance
of the class UndefinedObject.

00:02:13.920 --> 00:02:16.960 align:middle
So true, false, and nil
are objects like any other,

00:02:17.120 --> 00:02:21.200 align:middle
except they are the unique instances
of a specific class in the system.

00:02:21.800 --> 00:02:24.160 align:middle
Next, there are three pseudo-variables:

00:02:24.320 --> 00:02:28.720 align:middle
self refers to the current receiver,
and it's equivalent to this in Java.

00:02:28.880 --> 00:02:31.520 align:middle
super always refers
to the current receiver,

00:02:31.680 --> 00:02:34.880 align:middle
but this time, when you send
a message via super,

00:02:35.040 --> 00:02:38.720 align:middle
it means the method lookup,
the selection method algorithm,

00:02:38.880 --> 00:02:40.960 align:middle
which we will see in another class,

00:02:41.120 --> 00:02:45.840 align:middle
will start in the superclass
where the keyword super is written.

00:02:46.800 --> 00:02:51.000 align:middle
thisContext is a pseudo-variable
which refers to the object

00:02:51.160 --> 00:02:53.400 align:middle
that reifies the program's call stack.

00:02:53.560 --> 00:02:57.280 align:middle
It's an advanced concept
we'll study at the end of this MOOC.

00:02:57.440 --> 00:03:00.080 align:middle
We will explain it to you later.

00:03:00.240 --> 00:03:03.360 align:middle
For now, you just need to know
it's a pseudo-variable.

00:03:04.760 --> 00:03:08.120 align:middle
Now, shared or global variables.

00:03:08.280 --> 00:03:10.680 align:middle
First, you have all the classes.

00:03:10.840 --> 00:03:14.120 align:middle
All class names start with uppercase

00:03:14.280 --> 00:03:17.680 align:middle
because I can reference a class
from anywhere in the system.

00:03:18.480 --> 00:03:22.160 align:middle
Be careful: what starts
with uppercase is not always a class.

00:03:22.320 --> 00:03:24.600 align:middle
For example, Transcript:

00:03:24.760 --> 00:03:29.640 align:middle
it's an object name
shared in the system.

00:03:29.800 --> 00:03:32.840 align:middle
Everyone can reference this object.

00:03:33.000 --> 00:03:36.640 align:middle
And it's standard output,
stdout in other languages.

00:03:36.800 --> 00:03:40.120 align:middle
It's an instance object of a class,
globally accessible.

00:03:40.280 --> 00:03:42.880 align:middle
So its name starts with uppercase.

00:03:45.440 --> 00:03:48.280 align:middle
There are also class variables,

00:03:48.440 --> 00:03:52.840 align:middle
which are declared here when declaring
a class in classVariableNames;

00:03:53.000 --> 00:03:56.520 align:middle
here, the class #CombinedChar
defines two class variables,

00:03:56.680 --> 00:03:59.920 align:middle
one called Compositions
and the other Decompositions.

00:04:00.080 --> 00:04:02.200 align:middle
These two class variables

00:04:02.360 --> 00:04:06.040 align:middle
are accessible by the instances
of the class #CombinedChar

00:04:06.200 --> 00:04:09.000 align:middle
and of its subclasses.

00:04:09.160 --> 00:04:11.880 align:middle
That's why they're called
shared variables.

00:04:12.040 --> 00:04:15.480 align:middle
All the instances of the class
and its subclasses share them.

00:04:15.640 --> 00:04:19.240 align:middle
So both of them start with uppercase.

00:04:19.400 --> 00:04:22.080 align:middle
To summarize, you must remember:

00:04:22.240 --> 00:04:27.520 align:middle
all local variables, local to an object,
a block, or a method,

00:04:27.680 --> 00:04:29.760 align:middle
start with lowercase;

00:04:29.920 --> 00:04:33.600 align:middle
all global variables,
such as class names, etc.,

00:04:33.760 --> 00:04:35.600 align:middle
start with uppercase.