Let’s get you going with Pharo programming as quickly and as easily as possible. Starting from nothing, we shall write our very first Pharo program (“Hello World”) within 10 minutes.

Installing Pharo

From http://pharo.org/web/download, you can find downloads for Windows, macOS, and Linux. What you are actually downloading is the Pharo Launcher, a powerful tool that allows you to create a variety of Pharo images. You can then launch any of those images as you like.

cd pharo-location-folder
./pharo

Launching the Pharo image

When you start up the Pharo Launcher, you will see two sections: Templates and Existing images (which is initially empty). From the Templates side, we’ll pick on the latest stable official distribution (Pharo 6.1 at the time of writing). Right-click and choose “Create image”.

Transcript show: 'Hello World'

Getting acquainted with the Pharo IDE

Pharo’s System Browser is the main interface to the Pharo programming system. It’s much like today’s IDEs such as Eclipse and IntelliJ IDEA, only much simpler and more elegant. To open the System Browser, left-click on open space to bring up the World menu, then select System Browser.

  • the Classes pane is where you see all the classes for a particular package
  • the Protocols pane is where you see the logical groupings of methods for a particular class
  • the Methods pane is where you see the methods for a particular protocol
  • the Edit pane is where you can view, edit, or create new methods and classes
  • the Quality Assistant pane is where you can see helpful hints and tips for whatever you are currently editing

Creating a package and class for our Hello World program

For our Hello World program, we need to create a package and class for it. We shall name the class #Greeter and the package ‘HelloWorld’. Edit or type the following in the Edit pane:

Object subclass: #Greeter
instanceVariableNames: ''
classVariableNames: ''
package: 'HelloWorld'

Creating a method for our Hello World program

Now we need to create a method or function for our Greeter class. The standard first method is ‘initialize’ which is invoked when the Greeter class is instantiated (this is OOP parlance). For simplicity, we shall skip this.

sayIt
Transcript show: 'Hello World'

Executing our Hello World Program

Our Hello World program prints to the Transcript. To open the Transcript, left-click on open space to bring up the World menu, select Tools, and then select Transcript.

Greeter new sayIt

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store