Rethinking the Print It action in Pharo

In Smalltalk, "Print it" denotes the action of obtaining the textual representation of an object. It’s a great feature that can be used from any code editor to obtain a quick feedback.

The way it works goes like this. You select the text, then invoke print it (in Pharo, it works through Cmd+p), and you get the result as shown below.


This feature exists since decades, and it is implemented exactly like this in all Smalltalk-related system I know. Andrei and I considered it's time to rethink it.

Let's take a closer look at it. The main problem with the user interface solution is that the result of the action influences the content of the code editor. Imagine you have the following script:

aNumber := 40 + 1.
theNumber := aNumber + 1.


Printing the first line, inserts 41 in the code editor. As a result, the editor is marked as dirty, and the second line becomes red because the newly introduced 41 changes the semantics of the code.


Actually, I have never encountered a case in which I wanted to get the printed text in the same code editor. Granted, the 41 text gets selected and this makes it easy to press Backspace and erase the text. However, if you press an arrow key instead, the selection gets lost and you are left with the tedious job of manually selecting the printout text.

To improve this situation, a different solution is be to not insert it in the same editor, but to pop it up in a separate morph.


The original editor is left untouched. The popper morph takes the focus. When the printout is too large, the size of it can be contained and scrolled if needed. The popper is not modal. It goes away if you click anywhere else, or if you press Esc. And just to preserve the behavior that everyone else knows, it also goes away if you press Backspace as well.


While solving the initial problem, the popper also comes with a couple of interesting side effects. First, if you want to select something, you can either select everything through Cmd+a or select parts of it like in any text readonly editor.


But, there is a more interesting feature. Every once in a while you get to a piece of code that takes long to run. Let’s say it's kind of like this:

[ (Delay forSeconds: 10) wait. 42 ] value

What you really want to do is inspect the result, you do it, wait for the 10 seconds, only afterwards to realize you pressed Cmd+p instead. You just do not want to wait again just to inspect the result. What you want is to just press Cmd+i and inspect the object you already obtained. The popper let's you do exactly that either through the keybinding or by pressing the associated inspect icon.

The popper implementation ships with the latest version of the Glamorous Toolkit.

Inserting the printout in the same editor probably made sense at the time of the implementation, but it does not have to be the solution anymore. This little feature might sound trivial, and in a sense it is. But, to me it exhibits the opportunities that await at any corner in our environment. We just have to look it again.

Posted by Tudor Girba at 28 July 2014, 1:19 am with tags assessment, moose, pharo, analysis, tooling link