Search code examples
smalltalkpharo

In pharo, it's possible to run code inside both playground and transcript. When to do each?


In Pharo, it's usual to run code inside Playground, and using Transcript to print the output. But I noticed it's also possible to run code inside Transcript, not only printing things there. For example, if I type:

Transcript clear.

Inside the Transcript window, and run it by Ctrl+D, the window will be cleared. So my question is, when does make sense to run code inside the Transcript window instead of Playground? Is there a use case?


Solution

  • To answer your question, we need to clear some things out:

    You can run any code (almost) anywhere in the image. So if you open a method for example, type somewhere there Transcript clear, select it and hit Ctrl+D the transcript window will be cleared.

    Transcript is just a "singleton" linked to a window that makes it easy to output some text and see it somewhere. It's not hard to construct a similar functionality on your own, or you can even output to a file for example. Transcript is there just for convenience during a troubleshooting activity. I would still recommend to use the debugger in a first place, but there may be situations where a debugger won't cut it.

    Playground is a tool designed to "play" with your code. It's paired with an inspector, so whenever you run some code, you can inspect the resulting object in a user-friendly way. There are also some other features, like browsing variable bindings or storing code snippets, or browsing the playground code history. As I mentioned before you can run any code anywhere, but Playground is optimized for trying out stuff.