Updated: 11/11/2019
This partial we started learning the language Smalltalk through Pharo virtual machine.

One thing to understand about Smalltalk and pharo is that everything inside this virtual machine is an object, even simple numbers. Every object has its attributes and methods, Pharo already comes with lots of packages to start exploring, which can be opened in the system browser
There are 3 main windows pharo provides in order to meddle with the program:
Transcript window: This window is used as an output source for every print that is included in methods
Playground window: This window is used to access the different objects pharo has available and meddle with them. In summary this is, as it name suggests a playground for testing.
System browser window: This window is used to create, modify or classify the objects and methods present in the virtual machine.
Creating a new class:
To create a new object class we need to go into the system browser and select a package (or preferably create a new one). Here in the lower part of the window a template of a new class will show.

As seen in the picture above, we see the template of a class which will derivate from the Object class. Where the subclass is originated from can be changed, but for now it will remain like that.
The name is declared in the #NameOFSubclass, it is important to leave the # with the name.
The class can have instance variables which will change of value for each object created from this class, just like any other object oriented language. They are declared inside the ‘ ’ part separated with spaces.
The class can also have class variables which won’t change individually for each object created, instead these values will stick to the class statically and all objects created will share them. They are declared the same as the above.
For the package part, Pharo will be kind enough to be in charge of organizing classes, the package will be set automatically when a template appears, if you want to put other package rather than the current one, just replace the name and it will work. At the end the class should appear more or less like this:

To create the class you just save it (ctrl+S).
After these steps an error should appear saying something about not being a comment with the class. You can safely ignore this error, or if you prefer you can set a comment by clicking in the class name in the upper part of the window, a comment tab will appear where you can edit its contents.

Creating a method:
To create a new method you select the class you want in the upper side of the window, in the upper center then it should appear something called “instance side” or something else depending in your reference object. This part of the window is in charge of organizing the methods you create or override (because it is a subclass, you will have to override some methods like the initialize method).
If you click in the “instance side” text, a template in the lower part of the window should appear, this time it is the template to create a method.

Pharo tends to be very organized about its classes and methods, which is why the column in the middle (where “instance side” is) exists. This column is in charge of classifying methods, is your method a getter? Is it a setter? A constructor or some weird method you don’t know how to classify? You will surely want to classify them in this column. Of course this is Pharo’s ways to make it easier for us to understand our code, but it doesn’t mean you need to do it. You can ignore this column completely if you wish.
The messageSelectorAndArguments is a bit tricky part. It is the name of your method, but you can also declare a parameter with the method, like this:


Like most of programming languages, smalltalk lets you put an unlimited number of parameters, but how to put them is a bit tricky. As we know you declare a parameter by naming it and putting it next to the method name, but Smalltalk actually forces you to add an extra ”specifying” one-worded name just before the next parameter, this is made so that when you call the method in the playground you actually know where and in which order the parameters go.
A method with more than 1 parameter is declared like this:

These parameters, as expected, work like the parameters of any other common programming language, they are variables.
Commenting in your methods is really important to Pharo, hence why is it automatically writing a comment saying “comment stating purpose of message”. This is, as you probably guessed, completely optional.
Declaring temporary variable names is done at the very start of the method, it is declared as seen above, with the “||” characters, you can create as many variables as you wish, separated by a spacebar.
After the variables are declared, it’s time to actually write what your method will do, manipulating variables, parameters or attributes of the object.
The return statement is declared by the “^” character followed by the stuff you want to return. If you want to return multiple variables or as per usual, multiple strings, you could concatenate some objects separating them with a comma.
To access an attribute there is no fancy word like “this.”, you just write the name of the attribute and it will automatically detect it. This should be problematic if you have a local variable named the same as an attribute but in reality it isn’t. Smalltalk will be smart and will mark as an error when a local variable has the same name as an attribute.


With the information above, we can now create a method, something like this:

Our new created class will be in effect in the Playground window:

This window will be used to meddle and “play” with all the objects available. Create multiple objects, assign them values etc.
If you tinker with some of the available classes you can create useful software that has a GUI or maybe some data structures.

In order to execute a method from an object, like all object oriented programming, it is needed to create the object first, then asign it to a variable and then call the method as shown below.

One thing to know about Smalltalk is that to create a new instance of something, it is needed to specify the object first and then the “new” method.
The new method can actually be overriden for that specific class (since its a subclass) so we can initiate our instance or class attributes. The method needed to be overriden is called “initialize”. With this we can now ask for parameters at the initialization of the object.
With this you now may be able to play around Pharo and learned the basic stuff in this updated guide, at least for the year 2019.













