Learn how to use the Transcript

From Cuis CookBook
Jump to navigation Jump to search

Let's go step by step:

  • What is the most frequent command you ever type in a typical programming language? printf or one of its equivalent like print, cout, format, puts, console.log etc. Sure they are. It is the only (canonical) way you can get debug info while your program is running.
  • In Smalltalk, you can survive for a while without the print because Smalltalk lets you live-inspect and modify your objects (data structures) and code, while the code itself is running; often this provides much better view on the data than a brutal print. But in the end, you will need to print out long strings sooner or later and the inspector/explorer will not help you there.
  • What is the equivalent of print in Cuis-Smalltalk ? Well, you open a Transcript window with WorldClick -> Open -> Transcript, and then, from the Workspace you type:
Transcript log: 'Hello world!'.
  • and voilà, you get your output in the Transcript window.
  • Now, there are a few problems, try to load some larger text, for example the Wikipedia page for Verona ...
Feature require: 'WebClient'.
url _ 'https://en.wikipedia.org/wiki/Verona'.
Transcript show:  (WebClient httpGet: url) content. 
  • ... what you see in the Transcript is probably not what you were expecting.
  • Besides the missing wrapping, the Transcript by default also misses history and you can't copy chunk of text from it. You may not even have newlines represented. Would that be useful?
  • Here is the solution, just RightClick inside the Transcript and select Workspace with contents. That will open a Window where there is the same text available in the Transcript but the text behaves as you expect: line wrap, history, newlines.
  • Why then the Transcript behaves this way it does ?
  • Keeping the Transcript and the Workspace - Trscript Contents both open try to run this snippet in your Workspace:
1 to: 10 do: [ :i | i print. (Delay forSeconds: 0.2) wait ].
  • You will notice that in Transcript numbers appear immediately after print message is sent, in Workspace - Transcript Contents they appear where the whole loop is over. This because Workspace - Transcript Contents is a Morphic Window and gets updated only after your snippet execution is over, since your snippet is running in the World Morphic process. Transcript is not implemented in Morphic so it can print stuff even when you hanged the whole World, for any reason. Therefore we can conclude the Transcript is made to debug stuff but also and preeminently, to be lean, fast and resilient, it does not sport some of the niceties we are used to.
  • There is a way to let Transcript log to a file in your system. As of today 04-dec-2021 you can log to stdout or to a file named transcript.txt. Here follows the protocol :
Transcript logsToStdout.              "returns boolean"
Transcript logsToStdout: aBoolean.

Transcript logsToFile.                "returns boolean"
Transcript logsToFile: aBoolean.
Transcript filename.                   "=> transcript.txt'
  • NOTE. Transcript is quite an interesting Class per se, if you go to read it in the Browser you will see it has zero code in the instance side. All of the behavior is in the class side.