Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 38 ยท Tools and Image Workflow

The Inspector, Debugger and Playground

Learn the core Pharo tools: the Playground for experiments, the Inspector for looking inside objects, and the Debugger for fixing code live. Runnable JavaScript stand-ins model each idea.

Three tools carry most of everyday Smalltalk work. The Playground is where you type expressions and run them. The Inspector shows the inside of any object and lets you send messages to it. The Debugger opens when something goes wrong and lets you fix the code while the program is paused. Together they replace the edit-compile-run cycle with a conversation with live objects.

This lesson uses Pharo's names and shortcuts. Smalltalk does not run on this site, so the code and keystrokes are read-only. After each tool, a small JavaScript stand-in imitates what it does so you can experiment with the ideas.

The Playground

Open it from the Pharo menu. It is a text area where each selection can be run on its own. The most useful commands are (read-only):

Shortcut Action
Do it (Ctrl+D) Run the selection, show nothing
Print it (Ctrl+P) Run the selection and print the result after it
Inspect it (Ctrl+I) Run it and open an inspector on the result
Debug it Run the selection step by step in the debugger

Variables declared in the playground, such as | acct |, persist as bindings for the session, so you can build an object in one line and poke at it in the next.

SMALLTALK
acct := OrderedCollection new.
acct add: 10; add: 20; add: 30.
acct inject: 0 into: [ :sum :each | sum + each ].   "Print it: 60"

The Inspector

An inspector has tabs. Raw lists the instance variables with values; click one to drill down. Evaluator is a mini playground where self is the inspected object. Other tabs show a custom view, such as a table for collections or a picture for a form. You can edit a variable's value in place, which changes the real object.

Typical questions the inspector answers quickly: is this variable nil? Which class is this really? What is in this dictionary? What does self size or self first return right now?

Here is a runnable stand-in. A tiny inspect function walks an object and prints its structure with types, much like the Raw tab.

JS Stand-in: a text inspector

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The Debugger

When an error is not handled, Pharo opens the debugger with the stack at the point of failure, as described in thisContext and the execution stack. The window has four parts:

  1. The stack list, innermost call first.
  2. The source of the selected method, with the current message highlighted.
  3. The variables of that frame: receiver and temporaries.
  4. Buttons: Proceed, Restart, Into, Over, Through, Return, and tools to create a missing method.

Two features set it apart from debuggers in other languages. You can edit the method right in the debugger and Accept: the system recompiles it and, with Restart, reruns the frame with the corrected code. And when the error is "doesNotUnderstand", the debugger offers Create to write the missing method, so test-driven work happens inside it (read-only):

SMALLTALK
acct := Account new.
acct withdraw: 50.
"MessageNotUnderstood: Account>>withdraw:
 click Create -> choose protocol -> type the body -> Accept -> Proceed"

Always write the failing case as a test first, then use the debugger to drive the implementation. Testing with SUnit shows that workflow in full.

Stepping, modelled

Stepping means running one message send at a time. A stand-in can model the controls: a list of steps and a pointer, with Over (skip to the next step at the same level) and Into (enter the call).

JS Stand-in: stepping through a program

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Habits worth building

  • Use Print it and Inspect it constantly; they cost nothing.
  • Prefer self halt (read-only: it opens the debugger at that line) for quick checks, and remove it before you commit.
  • When a test fails, open the debugger from the test runner and fix the method there.
  • Learn the keyboard shortcuts: tool use is much faster once the mouse is out of the loop.

The next step is to share all this code safely: Monticello, Iceberg and Git.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command runs a selection and shows the result next to it?

    Print it shows the printString of the result; Do it runs silently.
  2. 2. What does the Evaluator tab of an inspector bind self to?

    Expressions typed there run with the inspected object as self.
  3. 3. What can you do in the debugger that is rare elsewhere?

    Because code and stack are live objects, the system recompiles and restarts the frame in place.
  4. 4. What does the Create button do on a MessageNotUnderstood error?

    It starts a new method for the unknown selector, supporting test-driven development.

Summary

  • The Playground runs expressions; Print it and Inspect it are the most used commands.
  • The Inspector shows and edits any object's variables and evaluates code with self bound to it.
  • The Debugger shows the stack, lets you edit and restart methods, and creates missing ones.
  • Work test-first and use the debugger to drive the implementation.
  • Keystrokes and Smalltalk code here are read-only; the JavaScript snippets are stand-ins.

Next: Monticello, Iceberg and Git