The Complete Pharo Guide: From Zero to Expert

a computer with a keyboard and mouse

The Complete Pharo Guide: From Zero to Expert

Pharo is a dynamic, open-source programming language and environment built on the principles of Smalltalk. It offers a uniquely immersive and interactive development experience where everything is a live object, allowing you to modify and debug your application while it's running, dramatically accelerating the development cycle.


The Agony of Modern Development and the Pharo Revelation

You've felt it, haven't you? The endless cycle of edit, compile, run, and debug. The frustration of complex toolchains, cryptic error messages, and a frustrating disconnect between the code you write and the system you're building. You spend more time fighting your tools than solving the actual problem.

Imagine a different world. A world where your code, your debugger, your IDE, and your running application are all part of a single, living, breathing entity. A place where an error isn't a dead end, but an invitation to pause, inspect the live state of your system, fix the code, and continue as if nothing happened. This isn't science fiction; this is the reality of developing in Pharo.

This comprehensive guide is your entry point into that world. We will take you from the foundational philosophy of Pharo to mastering its powerful tools and ecosystem. You will learn not just a new language, but a new, more powerful way of thinking about software development.


What Exactly is Pharo? The Living System

Pharo is not just a programming language; it's a complete, immersive environment. It is a modern, open-source implementation of the Smalltalk language and philosophy. The core idea is radical simplicity: everything in the system, from a number to a window, is an object. Programming in Pharo is done by sending messages to these objects.

The most defining feature of Pharo is its "image-based" persistence. Unlike traditional development where you save text files and compile them, in Pharo, you work within a "live image." This image is a memory snapshot of all the objects in your system, including your code, the IDE tools, and the state of your application. When you save, you're saving the entire running environment, ready to be resumed instantly.

This approach transforms development from a static, file-based process into a dynamic, interactive conversation with a live system. It's a paradigm shift that must be experienced to be fully understood.

  Host Operating System (Windows, macOS, Linux)
  ┌───────────────────────────────────────────────┐
  │                                               │
  │   Pharo Virtual Machine (VM)                  │
  │   (Executes bytecode, manages memory)         │
  │   ┌───────────────────────────────────────┐   │
  │   │                                       │   │
  │   │   Pharo Image (.image file)           │   │
  │   │   ● Live Objects                      │   │
  │   │   ● Compiled Code (Methods)           │   │
  │   │   ● Classes & Hierarchies             │   │
  │   │   ● IDE Tools (Browser, Debugger)     │   │
  │   │   ● Application State                 │   │
  │   │                                       │   │
  │   └───────────────────┬───────────────────┘   │
  │                       │                       │
  └───────────────────────┼───────────────────────┘
                          │
                          ▼
                  Saves changes to the .image file
                  and source code to .st files

Why Should You Invest Your Time in Learning Pharo?

In a world dominated by languages like Python, JavaScript, and Java, why choose Pharo? The reasons are compelling, especially for those who value productivity, simplicity, and power.

Unparalleled Live Coding and Debugging

Pharo's debugger is legendary. When an error occurs, the system doesn't crash. Instead, a debugger window opens with the full context of the error, including the complete call stack. You can inspect any object's state at any point in the stack, modify the code on the fly, recompile the method, and resume execution. This is often called "time-travel debugging" and it can reduce bug-fixing time from hours to minutes.

Radical Simplicity and Consistency

Pharo's syntax is incredibly small and consistent. There are only six reserved keywords. Everything is an object, and all computation is performed by sending messages to objects. This pure object-oriented model eliminates the countless special cases and inconsistencies found in many other languages, making it easier to learn and reason about.

A Powerful, Integrated Development Environment (IDE)

The Pharo environment is the IDE. The code browser, inspector, playground, and debugger are all built in Pharo itself. This means they are just as malleable and extensible as your own application code. You can inspect the IDE's own objects, modify its behavior, and tailor it to your exact needs, all while it's running.

Ideal for Complex and Exploratory Projects

The live, interactive nature of Pharo makes it exceptionally well-suited for research, data visualization, AI, and complex domain modeling. When you're not sure what the final solution looks like, Pharo allows you to explore, prototype, and evolve your system organically in a way that file-based languages simply cannot match.


How to Get Started: Your First Steps into the Pharo World

Getting started with Pharo is straightforward. The primary tool you'll use is the Pharo Launcher, which manages different Pharo images and virtual machines.

Step 1: Installation

First, download the Pharo Launcher for your operating system (Windows, macOS, or Linux) from the official Pharo website. It's a single executable with no complex installation process.

For Linux users, you can often use a simple command:


# On Debian/Ubuntu based systems
curl -L https://get.pharo.org/linux64/ | bash

Step 2: Launching Your First Image

Open the Pharo Launcher. You'll see a list of available Pharo images. For beginners, it's best to start with the latest stable release (e.g., Pharo 11 or newer).

  1. Select a recent Pharo image template from the list.
  2. Click the "Create Image" button.
  3. Give your new image a name (e.g., MyFirstProject).
  4. Once created, select your image and click "Launch".

The Pharo environment window will open, presenting you with a clean, object-oriented world ready for exploration.

Step 3: "Hello, World!" in the Playground

The "Playground" is an interactive scratchpad for writing and executing Pharo code. You can open one by clicking anywhere on the Pharo background and selecting "Playground" from the world menu.

Type the following line into the Playground:


Transcript show: 'Hello, Kodikra!'.

Now, highlight the text you just typed and press Ctrl+D (for "Do It"). This executes the code. The string 'Hello, Kodikra!' will appear in the Transcript window (a system console). Congratulations, you've just sent your first message in Pharo!

  • Transcript is the object representing the console window.
  • show: is the message (method name) you are sending to the Transcript object.
  • 'Hello, Kodikra!' is the argument (also an object) for the message.

The Core Language: Understanding Pharo's Elegant Syntax

Pharo's syntax is one of its most celebrated features. It's designed for readability and simplicity, resembling natural language. All syntax revolves around sending messages to objects.

Message Types

There are three types of messages in Pharo, evaluated in a specific order of precedence:

1. Unary Messages

These are messages with no arguments. They are evaluated first.


| aDate |
aDate := Date today. "Send the 'today' message to the Date class object"
aDate monthName. "Send the 'monthName' message to the aDate instance"

2. Binary Messages

These are messages with a single argument, typically used for arithmetic and comparison. They consist of one or two special characters. They are evaluated second.


3 + 4. "Sends the message '+' with argument 4 to the object 3"
10 > 5. "Sends the message '>' with argument 5 to the object 10"

3. Keyword Messages

These messages can take one or more arguments, with each part of the message name (the "keyword") ending in a colon. They are evaluated last.


| aCollection |
aCollection := OrderedCollection new.
aCollection add: 'Pharo'. "A message with one keyword: 'add:'"
aCollection addAll: #('is' 'powerful'). "A message with one keyword: 'addAll:'"

'hello' copyFrom: 2 to: 4. "A message with two keywords: 'copyFrom:to:'"

Variables and Assignment

Variables are declared between vertical bars | |. The assignment operator is :=.


| myVariable |
myVariable := 100.
myVariable := myVariable * 2.
Transcript show: myVariable asString. "Outputs '200'"

Blocks (Closures)

Blocks are Pharo's version of anonymous functions or lambdas. They are first-class objects enclosed in square brackets [ ] and are used extensively for control structures and iteration.


| aBlock |
aBlock := [ :x | x * x ]. "A block that takes one argument 'x' and returns its square"

aBlock value: 5. "Returns 25"

"Using a block for iteration"
#(1 2 3) do: [ :eachNumber |
    Transcript show: eachNumber asString; cr.
].

Mastering Object-Oriented Programming in Pharo

Pharo is not just object-oriented; it is purely object-oriented. This consistency is a source of great power. Learning OOP in Pharo means truly understanding the paradigm at its core.

Classes and Objects

A class is a blueprint for objects. It defines the structure (instance variables) and behavior (methods) that its instances will have. To create a new class, you use the System Browser.

Let's define a simple Counter class:


Object subclass: #Counter
    instanceVariableNames: 'count'
    classVariableNames: ''
    package: 'MyFirstProject'

This defines a class named Counter that inherits from Object and has one instance variable, count.

Methods and Behavior

Methods define how an object responds to messages. We can add methods to our Counter class.


"In class Counter"

initialize
    "Initialize the counter to zero."
    super initialize.
    count := 0.

increment
    "Increment the counter by one."
    count := count + 1.

count
    "Answer the current count."
    ^ count "The ^ character means 'return'"

Creating and Using Instances

You create an instance of a class by sending it the new message. Then you can interact with the instance by sending it messages.


| myCounter |
myCounter := Counter new. "Creates a new instance, which also calls our 'initialize' method"
myCounter increment.
myCounter increment.
Transcript show: myCounter count asString. "Outputs '2'"

This deep dive into OOP is the cornerstone of the Pharo Learning Roadmap available at kodikra.com. Our structured modules will guide you through these concepts with hands-on challenges.


The Pharo IDE: Your Live Coding Cockpit

The Pharo IDE is not a separate application but a collection of powerful tools that are themselves Pharo objects. This makes the entire environment incredibly dynamic and introspective.

The System Browser

This is your main window into the Pharo world. It allows you to navigate through all the code in the system—your code, the framework's code, and the IDE's own code—using a four-pane layout: Packages, Classes, Protocols (method categories), and Methods.

The Inspector

The Inspector is a tool for looking inside any object. You can select an object (or the result of a code execution) and "inspect" it. The Inspector shows you the object's instance variables and their current values. Because these values are live, you can even change them directly in the Inspector to see how it affects your running application.

The Debugger: A Paradigm Shift

Pharo's debugger is its killer feature. When an exception is raised, the execution is paused, and the debugger opens, showing you the exact state of the program at the moment of the error. This is not a post-mortem log file; it's a live, interactive session.

The workflow fundamentally changes how you fix bugs:

    ● Code Execution
    │
    ▼
   💥 Halt or Exception Occurs
    │
    ▼
  ┌──────────────────────┐
  │ Debugger Opens       │
  │ (Execution is PAUSED)│
  └──────────┬───────────┘
             │
             ▼
      ◆ Explore Live State
     ╱         │         ╲
Inspect   Modify Code   Restart
Objects     in Stack     Method
   │           │           │
   ▼           ▼           ▼
[Understand] [Live Compile] [Retry]
   │           │           │
   └───────────┼───────────┘
               │
               ▼
           ● Resume Execution

You can browse the call stack, inspect variables at each level, write and execute new code in the context of a stack frame, change the code of a faulty method, recompile it, and simply click "Proceed" to continue execution from the point of the error. This flow is incredibly powerful and efficient.


The Pharo Ecosystem: Frameworks and Libraries

While the core Pharo system is powerful, its true potential is unlocked through its rich ecosystem of frameworks and libraries, all easily loadable using the built-in package manager, Metacello.

Web Development with Seaside

Seaside is a highly innovative web framework for Pharo. It's known for its component-based architecture and its unique way of managing session state, which makes developing complex, stateful web applications remarkably simple and robust.

Data Visualization with Roassal

Roassal is a visualization engine for Pharo. It provides a flexible and scriptable platform for creating custom charts, diagrams, and interactive visualizations. Because it's integrated into the live Pharo environment, you can build and manipulate complex visualizations programmatically and interactively.

GUI Development with Morphic

Morphic is the UI framework used to build the Pharo IDE itself. It's a direct manipulation, event-driven framework that allows you to build graphical user interfaces. Since the IDE is built with it, you can inspect and modify any UI element in the system.

Interoperability

Pharo is not an island. It has robust mechanisms for interacting with the outside world, including:

  • FFI (Foreign Function Interface): Call C libraries directly from Pharo.
  • OSProcess: Run and communicate with external operating system processes.
  • NativeBoost: A high-performance FFI that allows for seamless integration with native libraries.
  • Socket and HTTP libraries: For all your networking needs.

Pros and Cons of Using Pharo

Like any technology, Pharo has its strengths and weaknesses. It's important to understand them to know when Pharo is the right tool for the job.

Pros (Strengths) Cons (Challenges)
Exceptional Productivity: The live coding and debugging environment drastically reduces development and bug-fixing time. Smaller Community: The community is smaller and more niche compared to mainstream languages like Python or JavaScript.
Simplicity and Purity: The pure object model and minimal syntax make the language easy to learn and reason about. Learning Curve for the Environment: The image-based approach is a paradigm shift and can be unfamiliar to developers from file-based backgrounds.
Powerful Tooling: The integrated IDE tools (debugger, inspector, browser) are second to none. Deployment: Deploying Pharo applications can be different from traditional methods, though tools like the Pharo Docker image are improving this.
Excellent for Complex Systems: Ideal for exploratory programming, research, and modeling complex domains where requirements are not fully known upfront. Fewer Off-the-Shelf Libraries: While the ecosystem is rich, it may not have a pre-built library for every specific, modern third-party API.
Highly Malleable System: The entire environment, including the IDE, can be modified and extended at runtime. Perception and Hiring: Pharo is not as well-known in the industry, which can be a factor in team building and project adoption.

Your Learning Path at Kodikra

At Kodikra, we've developed an exclusive, hands-on learning path to guide you from a complete beginner to a confident Pharo developer. Each module in our curriculum is designed to build upon the last, providing practical challenges to solidify your understanding.

This structured approach ensures you build a solid foundation. Explore the complete Pharo Learning Roadmap to start your journey.


Frequently Asked Questions (FAQ) about Pharo

Is Pharo still relevant today?

Absolutely. While it's a niche language, its principles of live programming and simplicity are more relevant than ever in an age of increasing software complexity. It excels in areas like data visualization, research, education, and building complex, long-lived enterprise systems.

Is Pharo the same as Smalltalk?

Pharo is a modern dialect of Smalltalk. It inherits the core language, philosophy, and design from Smalltalk-80 but is an actively developed, open-source project with a modern toolchain, a vibrant community, and a focus on contemporary use cases.

Can I use Pharo for web development?

Yes. The primary framework for web development in Pharo is Seaside. It's a powerful framework for building complex, stateful web applications. There are also libraries for building REST APIs, such as Teapot.

How do I manage dependencies and packages in Pharo?

Dependency management is typically handled by Metacello, a scriptable package management tool. You define your project's dependencies in a Metacello configuration script, which can then be used to load all required code into your image from repositories like GitHub.

What is the difference between an image and source files?

The .image file is a snapshot of all the live objects in your environment. It's how you save your session. The source code for your methods is typically saved to separate plain text .st ("source") files as a backup and for use with version control systems like Git. The image is for liveness; the source files are for history and sharing.

Is Pharo difficult to learn?

The language syntax itself is one of the simplest in existence and can be learned in an afternoon. The main learning curve is adapting to the live, image-based environment and its powerful tools. Once you overcome this initial conceptual hurdle, development becomes incredibly fast and intuitive.

What are the career opportunities for a Pharo developer?

Pharo developers often work in specialized roles in finance, research, data science, and on complex industrial or enterprise systems. While the number of job postings is lower than for mainstream languages, the roles are often high-impact and require a deep understanding of software design. The skills learned in Pharo—strong OOP, debugging, and system thinking—are highly transferable.


Conclusion: A More Human Way to Code

Pharo is more than just another programming language. It is a powerful idea—that software development should be a live, interactive, and joyful process. It challenges the rigid, batch-oriented cycle of modern development and offers a more fluid, powerful, and ultimately more human way to build complex systems.

By embracing Pharo, you are not just learning a new syntax; you are learning to think differently about software. You are empowering yourself with tools that let you stay "in the zone," molding and shaping a live system rather than just writing static text files. Whether you are building a complex data visualization, a robust web application, or simply exploring the art of programming, Pharo offers a unique and rewarding journey.

Ready to begin? Dive into the exclusive Pharo modules on kodikra.com and experience the future of programming, today.

Disclaimer: All code examples and concepts are based on modern Pharo versions (10+). The Pharo environment is constantly evolving, so be sure to consult the official documentation for the latest updates.


Published by Kodikra — Your trusted Pharo learning resource.