Pharo by Example

Andrew P. Black Stéphane Ducasse
Oscar Nierstrasz Damien Pollet
with Damien Cassou and Marcus Denker

Version of 2011-05-14
 

This book is available as a free download from http://PharoByExample.org.

Copyright © 2007, 2008, 2009 by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz and Damien Pollet.

The contents of this book are protected under Creative Commons Attribution-ShareAlike 3.0 Unported license.

You are free:

to Share
— to copy, distribute and transmit the work
to Remix
— to adapt the work

Under the following conditions:

Attribution.
You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
Share Alike.
If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.

PIC Your fair dealing and other rights are in no way affected by the above. This is a human-readable summary of the Legal Code (the full license):
creativecommons.org/licenses/by-sa/3.0/legalcode
Published by Square Bracket Associates, Switzerland. http://SquareBracketAssociates.org
ISBN 978-3-9523341-4-0
First Edition, October, 2009. Cover art by Samuel Morello.

Contents
Preface
 What is Pharo?
 Who should read this book?
 A word of advice
 An open book
 The Pharo community
 Examples and exercises
 Acknowledgments
1 A quick tour of Pharo
 1.1 Getting started
 1.2 The World menu
 1.3 Sending messages
 1.4 Saving, quitting and restarting a Pharo session
 1.5 Workspaces and Transcripts
 1.6 Keyboard shortcuts
 1.7 The Class Browser
 1.8 Finding classes
 1.9 Finding methods
 1.10 Defining a new method
 1.11 Chapter summary
2 A first application
 2.1 The Lights Out game
 2.2 Creating a new Package
 2.3 Defining the class LOCell
 2.4 Adding methods to a class
 2.5 Inspecting an object
 2.6 Defining the class LOGame
 2.7 Organizing methods into protocols
 2.8 Let’s try our code
 2.9 Saving and sharing Smalltalk code
 2.10 Chapter summary
3 Syntax in a nutshell
 3.1 Syntactic elements
 3.2 Pseudo-variables
 3.3 Message sends
 3.4 Method syntax
 3.5 Block syntax
 3.6 Conditionals and loops in a nutshell
 3.7 Primitives and pragmas
 3.8 Chapter summary
4 Understanding message syntax
 4.1 Identifying messages
 4.2 Three kinds of messages
 4.3 Message composition
 4.4 Hints for identifying keyword messages
 4.5 Expression sequences
 4.6 Cascaded messages
 4.7 Chapter summary
5 The Smalltalk object model
 5.1 The rules of the model
 5.2 Everything is an Object
 5.3 Every object is an instance of a class
 5.4 Every class has a superclass
 5.5 Everything happens by sending messages
 5.6 Method lookup follows the inheritance chain
 5.7 Shared variables
 5.8 Chapter summary
6 The Pharo programming environment
 6.1 Overview
 6.2 The Browser
 6.3 Monticello
 6.4 The Inspector and the Explorer
 6.5 The Debugger
 6.6 The Process Browser
 6.7 Finding methods
 6.8 Change sets and the Change Sorter
 6.9 The File List Browser
 6.10 In Smalltalk, you can’t lose code
 6.11 Chapter summary
7 SUnit
 7.1 Introduction
 7.2 Why testing is important
 7.3 What makes a good test?
 7.4 SUnit by example
 7.5 The SUnit cook book
 7.6 The SUnit framework
 7.7 Advanced features of SUnit
 7.8 The implementation of SUnit
 7.9 Some advice on testing
 7.10 Chapter summary
8 Basic Classes
 8.1 Object
 8.2 Numbers
 8.3 Characters
 8.4 Strings
 8.5 Booleans
 8.6 Chapter summary
9 Collections
 9.1 Introduction
 9.2 The varieties of collections
 9.3 Implementations of collections
 9.4 Examples of key classes
 9.5 Collection iterators
 9.6 Some hints for using collections
 9.7 Chapter summary
10 Streams
 10.1 Two sequences of elements
 10.2 Streams vs. collections
 10.3 Streaming over collections
 10.4 Using streams for file access
 10.5 Chapter summary
11 Morphic
 11.1 The history of Morphic
 11.2 Manipulating morphs
 11.3 Composing morphs
 11.4 Creating and drawing your own morphs
 11.5 Interaction and animation
 11.6 Interactors
 11.7 Drag-and-drop
 11.8 A complete example
 11.9 More about the canvas
 11.10 Chapter summary
12 Seaside by Example
 12.1 Why do we need Seaside?
 12.2 Getting started
 12.3 Seaside components
 12.4 Rendering XHTML
 12.5 CSS: Cascading style sheets
 12.6 Managing control flow
 12.7 A complete tutorial example
 12.8 A quick look at AJAX
 12.9 Chapter summary
13 Classes and metaclasses
 13.1 Rules for classes and metaclasses
 13.2 Revisiting the Smalltalk object model
 13.3 Every class is an instance of a metaclass
 13.4 The metaclass hierarchy parallels the class hierarchy
 13.5 Every metaclass Inherits from Class and Behavior
 13.6 Every metaclass is an instance of Metaclass
 13.7 The metaclass of Metaclass is an Instance of Metaclass
 13.8 Chapter summary
14 Reflection
 14.1 Introspection
 14.2 Browsing code
 14.3 Classes, method dictionaries and methods
 14.4 Browsing environments
 14.5 Accessing the run-time context
 14.6 Intercepting messages not understood
 14.7 Objects as method wrappers
 14.8 Pragmas
 14.9 Chapter summary
A Frequently Asked Questions
 A.1 Getting started
 A.2 Collections
 A.3 Browsing the system
 A.4 Using Monticello and SqueakSource
 A.5 Tools
 A.6 Regular expressions and parsing
Bibliography