Book Reviews

Learning Smalltalk from Pharo by Example

Homepage: Pharo by Example - free download
Pages: 350 (pdf)

I was close to become a Smalltalk programmer back in 2005. At that time I worked in a large company. Somewhere in a dusty corner of the corporation there was a skilled team of Smalltalk programmers. These programmers were responsible for a bunch of legacy applications. Since I've heard a lot of interesting things about Smalltalk from smart people, I decided to dive into the language by joining that team. Unfortunately it became a short ride; On my first day in my new Smalltalk team a management decision was made to outsource the development. A terrible decision for the company, it turned out, and bad timing for me indeed. I went back to other languages and ten years passed. Then I met Tudor Girba at a conference last year. Tudor told me about this cool, modern open source Smalltalk implementation called Pharo. I decided to finally give Smalltalk a chance by working through the book Pharo by Example. What I found was something I've searched for years; an interactive, live environment that allows us to develop programs in a way that fits the way our brains are wired.

Smalltalk is actually made up of two axes that have to be considered together. The first is the language itself so let's start there. The Smalltalk syntax is elegant and minimalistic. Everything in the language is consistent and built around message passing; If you want something to happen, you send a message to an object. Now, message passing is not the same thing as invoking a method like we do in C++, Java or C#. With message passing, an object may understand the message and react or it might just not know what you mean. This style is reminiscent of communication in the real world and one of the fundamentals that gives Smalltalk an edge. Another contrast to more popular object-oriented languages is that Smalltalk takes message passing all the way. For example, object creation is done by sending a message to the class you want an instance of. You see, in Smalltalk classes are objects too (classes are just instances of metaclasses). Similar, conditional forms like if-then-else logic are nothing special. They're just messages to boolean objects.

Smalltalk's minimalism is one of its strengths. Essentially the only thing there's syntax for is sending messages. Since there's only six reserved keywords to learn (self, super, nil, true, false and thisContext), it's pretty easy to read Smalltalk code. Smalltalk is simplicity for real.

Remember that I told you how Smalltalk is made up of two axes? The language is the first one and the environment the second. While Pharo the language is nice, there are other languages that are just as powerful. What sets Pharo apart is the environment. First of all, it's incredibly easy to get started with Pharo. You just download an image and launch it. That image contains everything you need: a powerful editor, debuggers and inspectors, refactoring support and even Monticello which is a distributed version-control system tailored to Smalltalk. Of course that environment is in itself written in Pharo. That means you can inspect it, modify it and grow it if you want.

The openness of Pharo is not just about flexibility and practical tools. The environment facilitates learning as well. As a beginning Smalltalk programmer I like to be able to browse the implementation of the language, look at library methods and pick-up the style and idioms of the contributors. It's a great way to learn. But the main advantage I see in the Pharo environment is that it enables a much more interactive development style. And it feels natural.

A programmable environment where you can play around with live objects makes all the difference. Programming in its basic form is problem-solving. As such, programming is an inherently iterative activity and developing a program is a constant feedback-driven learning experience. You can emulate that to a certain extent with techniques like Test-Driven Development, but with Pharo you're shortening the feedback cycle even more - Pharo is the first development environment I've found that actually supports the nature of programming rather than fighting it. Until now I've only written small Pharo programs, but I've found that my development style is different. I start by coding out some dumb object without much behavior. Once I've instantiated that object I start to interact with it. I add new methods, refactor existing ones and keep growing the code while keeping my program running all the time. This interactivity is a great way to build programs. I was surprised by the power and I say that as a Lisp programmer that's used to modifying live systems.

So, let's discuss the book I used to learn Pharo: Pharo by Example. In short, it's a great book that gets you up and running with real programs in just a few chapters. The problem is that the book is somewhat outdated. Pharo the environment has evolved at a rapid rate and the book hasn't kept up. That means some of the menus and tools will look differently than what's described in the book. It wasn't a big problem for me, but it's definitely an extra hurdle when learning a new technology. Particularly since the first example in the book, a visualization of bouncing atoms, doesn't work out of the box. Pharo by Example would definitely need a new updated revision.

That said, what I like in particular about Pharo by Example is that it immediately gives you a high-level feel for the language. The first 40 pages were enough to cover the bulk of the language and learn enough to develop some programs of my own. The rest of the book dives deeper into the language. You get to learn about basic building blocks like the collection API and unit testing, but also more advanced concepts like user interfaces, web development and metaclasses. Overall, this is a solid introduction to the most amazing technology I've worked with since I discovered Lisp and Erlang a decade ago. I do recommend that you give Pharo a try even if you don't intend to use Smalltalk in your daily work. The kind of flow that the environment enables is worth to experience for every programmer that's serious about developing better software. So stay tuned and I'll get back with more experience reports once I've written some more elaborate programs. I sure will - programming in this beautiful environment is a lot of fun!

Reviewed February 2015