Squeak by Example

(0 reviews)

star01star02star03star04star05

Andrew Black, Portland State University
Stéphane Ducasse, INRIA Lille
Oscar Nierstrasz, University of Bern
Damien Pollet, University of Lille

Pub Date: 2009

ISBN 13: 978-3-9523341-0-2

Publisher: Independent

Read This Book

Conditions of Use

Attribution-ShareAlike
CC BY-SA

Reviews

  All reviews are licensed under a CC BY-ND license.

Learn more about reviews.

There are no reviews for this book






Table of Contents

I Getting Started
 
1 A quick tour of Squeak 3
1.1 Getting started . . . . . . . . . . . . . . . . . 3
1.2 TheWorld menu . . . . . . . . . . . . . . . . 7
1.3 Saving, quitting and restarting a Squeak session . . . . . 9
1.4 Workspaces and Transcripts . . . . . . . . . . . . 11
1.5 Keyboard shortcuts . . . . . . . . . . . . . . . 12
1.6 SqueakMap . . . . . . . . . . . . . . . . . . 15
1.7 The System Browser . . . . . . . . . . . . . . . 17
1.8 Finding classes . . . . . . . . . . . . . . . . . 18
1.9 Finding methods . . . . . . . . . . . . . . . . 20
1.10 Defining a new method. . . . . . . . . . . . . . 21
1.11 Chapter summary. . . . . . . . . . . . . . . . 26
 
2 A first application 29
2.1 The Quinto game . . . . . . . . . . . . . . . . 29
2.2 Creating a new class Category . . . . . . . . . . . 30
2.3 Defining the class SBECell . . . . . . . . . . . . . 31
2.4 Adding methods to a class. . . . . . . . . . . . . 32
2.5 Inspecting an object . . . . . . . . . . . . . . . 34
2.6 Defining the class SBEGame . . . . . . . . . . . . 36
2.7 Organizing methods into protocols . . . . . . . . . 39
2.8 Let’s try our code . . . . . . . . . . . . . . . . 42
2.9 Saving and sharing Smalltalk code. . . . . . . . 45
2.10 Chapter summary. . . . . . . . . . . . . . . . 49
 
3 Syntax in a nutshell 51
3.1 Syntactic elements . . . . . . . . . . . . . . . 51
3.2 Pseudo-variables . . . . . . . . . . . . . . . . 54
3.3 Message sends . . . . . . . . . . . . . . . . . 55
3.4 Method syntax . . . . . . . . . . . . . . . . . 56
3.5 Block syntax . . . . . . . . . . . . . . . . . . 57
3.6 Conditionals and loops in a nutshell . . . . . . 58
3.7 Primitives and pragmas . . . . . . . . . . . . . 60
3.8 Chapter summary. . . . . . . . . . . . . . . . 61
 
4 Understanding message syntax 63
4.1 Identifying messages . . . . . . . . . . . . . . 63
4.2 Three kinds of messages . . . . . . . . . . . . . 65
4.3 Message composition . . . . . . . . . . . . . . 68
4.4 Hints for identifying keyword messages . . . . . 74
4.5 Expression sequences . . . . . . . . . . . . . . 76
4.6 Cascaded messages . . . . . . . . . . . . . . . 76
4.7 Chapter summary. . . . . . . . . . . . . . . . 76
 
II Developing in Squeak
 
5 The Smalltalk object model 81
5.1 The rules of the model . . . . . . . . . . . . . . 81
5.2 Everything is an Object . . . . . . . . . . . . . . 81
5.3 Every object is an instance of a class . . . . . . . 82
5.4 Every class has a superclass . . . . . . . . . . . . 89
5.5 Everything happens by message sending . . . . . . . 93
5.6 Method lookup follows the inheritance chain . . . . 94
5.7 Shared variables . . . . . . . . . . . . . . . . 101
5.8 Chapter summary. . . . . . . . . . . . . . . . 106
 
6 The Squeak programming environment 109
6.1 Overview . . . . . . . . . . . . . . . . . . . 110
6.2 The System Browser . . . . . . . . . . . . . . 111
6.3 Monticello . . . . . . . . . . . . . . . . . . 124
6.4 The Inspector and the Explorer . . . . . . . . 132
6.5 The Debugger . . . . . . . . . . . . . . . . . 135
6.6 The Process Browser . . . . . . . . . . . . . .144
6.7 Finding methods . . . . . . . . . . . . . . . .145
6.8 Change sets and the Change Sorter . . . . . . . .146
6.9 The File List Browser . . . . . . . . . . . . . .148
6.10 In Smalltalk, you can’t lose code . . . . . . . .151
6.11 Chapter summary. . . . . . . . . . . . . . . . 152
 
7 SUnit 155
7.1 Introduction . . . . . . . . . . . . . . . . . . 155
7.2 Why testing is important . . . . . . . . . . . . . 156
7.3 What makes a good test? . . . . . . . . . . . . . 157
7.4 SUnit by example . . . . . . . . . . . . . . . . 158
7.5 The SUnit cook book. . . . . . . . . . . . . . . 162
7.6 The SUnit framework . . . . . . . . . . . . . . 164
7.7 Advanced features of SUnit . . . . . . . . . . . . 166
7.8 The implementation of SUnit. . . . . . . . . . . . 168
7.9 Some advice on testing . . . . . . . . . . . . . . 171
7.10 Chapter summary. . . . . . . . . . . . . . . . 172
 
8 Basic Classes 175
8.1 Object . . . . . . . . . . . . . . . . . . . . 175
8.2 Numbers . . . . . . . . . . . . . . . . . . . 184
8.3 Characters . . . . . . . . . . . . . . . . . . 188
8.4 Strings . . . . . . . . . . . . . . . . . . . . 189
8.5 Booleans . . . . . . . . . . . . . . . . . . . 190
8.6 Chapter summary. . . . . . . . . . . . . . . . 192
 
9 Collections 193
9.1 Introduction . . . . . . . . . . . . . . . . . . 193
9.2 The varieties of collections. . . . . . . . . . . . 195
9.3 Implementations of collections . . . . . . . . . . . 198
9.4 Examples of key classes. . . . . . . . . . . . . . 199
9.5 Collection iterators . . . . . . . . . . . . . . . 209
9.6 Some hints for using collections . . . . . . . . . 213
9.7 Chapter summary. . . . . . . . . . . . . . . . 214
 
10 Streams 217
10.1 Two sequences of elements . . . . . . . . . . . . 217
10.2 Streams vs. collections . . . . . . . . . . . . . . 218
10.3 Streaming over collections. . . . . . . . . . . . . 219
10.4 Using streams for file access . . . . . . . . . . . 227
10.5 Chapter summary. . . . . . . . . . . . . . . . 230
 
11 Morphic 231
11.1 The history of Morphic . . . . . . . . . . . . . . 231
11.2 Manipulating morphs . . . . . . . . . . . . . . 233
11.3 Composing morphs . . . . . . . . . . . . . . . 233
11.4 Creating and drawing your own morphs . . . . . . 235
11.5 Interaction and animation . . . . . . . . . . . .239
11.6 Interactors . . . . . . . . . . . . . . . . . . 242
11.7 Drag-and-drop . . . . . . . . . . . . . . . . . 243
11.8 A complete example . . . . . . . . . . . . . . . 245
11.9 More about the canvas . . . . . . . . . . . . . . 249
11.10 Chapter summary. . . . . . . . . . . . . . . . 250
 
III Advanced Squeak
 
12 Classes and metaclasses 255
12.1 Rules for classes and metaclasses . . . . . . . . . . 255
12.2 Revisiting the Smalltalk object model. . . . . . . . . 256
12.3 Every class is an instance of a metaclass . . . . . . . . 258
12.4 The metaclass hierarchy parallels the class hierarchy . . . 259
12.5 Every metaclass Inherits from Class and Behavior . . . . . 261

About the Book

Squeak is a modern open-source development environment for the classic Smalltalk-80 programming language. Despite being the first purely object-oriented language and environment, Smalltalk is in many ways still far ahead of its successors in promoting a vision of an environment where everything is an object, and anything can change at run-time.

Squeak by Example, intended for both students and developers, will guide you gently through the Squeak language and environment by means of a series of examples and exercises. The book helps you get started with A Quick Tour of Squeak and guides you through A First Application. The Smalltalk language is introduced in three chapters on Syntax in a Nutshell, Understanding Message Syntax and The Smalltalk Object Model.

Development with Squeak is covered in The Squeak Programming Environment and SUnit. Several of the key classes are presented in chapters on Basic Classes, Collections, Streams and Morphic.

The first edition of the book concludes with chapters on Classes and Metaclasses and Frequently Asked Questions.

About the Contributors

Author(s)

Andrew P. Black, Professor, Department of Computer Science, Portland State University. D.Phil., Programming Research Group, University of Oxford (England).

Stéphane Ducasse is the research director at INRIA Lille leading the RMoD Team. 

Oscar Nierstrasz is Professor of Computer Science at the Institute of Computer Science (IAM) of the University of Bern, where he founded the Software Composition Group in 1994. He is co-author of over 200 publications and co-author of the open-source books Object-Oriented Reengineering Patterns and Pharo by Example.

Damien Pollet, associate professor (Maître de conférences) of the UFR IEEA at University of Lille 1 since september 2008, and affiliated with the Laboratoire d’Informatique Fondamentale de Lille (LIFL), the joint laboratory between Lille 1, Lille 3, CNRS, and Inria. Pollet teaches programming and software engineering at Telecom Lille 1, and research on programming languages and reengineering within the RMoD project-team of Inria.