Skip to main content
Engineering LibreTexts

6.4: The Inspector and the Explorer

  • Page ID
    36363
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    One of the things that makes Smalltalk so different from many other programming environments is that it is provides you with a window onto a world of live objects, not a world of static code. Any of those objects can be examined by the programmer, and even changed — although some care is necessary when changing the basic objects that support the system. By all means experiment, but save your image first!

    The Inspector

    \(\bigstar\) As an illustration of what you can do with an inspector, type TimeStamp now in a workspace, and then choose inspect it from the yellow button menu.

    (It’s not necessary to select the text before using the menu; if no text is selected, the menu operations work on the whole of the current line. You can also type CMD–i for inspect it.)

    A window like that shown in Figure \(\PageIndex{1}\) will appear. This is an inspector, and can be thought of as a window onto the internals of a particular object — in this case, the particular instance of TimeStamp that was created when you evaluated the expression TimeStamp now. The title bar of the window shows the class of the object that is being inspected. If you select self at the top of the left pane, the right pane will show the printstring of the object. If you select all inst vars in the left pane, the right pane will show a list of the instance variables in the object, and the printstring for each one. The remaining items in the left pane represent the instance variables; this makes it easy to examine them one at a time, and also to change them.

    Inspecting TimeStamp now.
    Figure \(\PageIndex{1}\): Inspecting TimeStamp now.

    The horizontal pane at the bottom of the inspector is a small workspace window. It is useful because in this window, the pseudo-variable self is bound to the very object that you are inspecting. So, if you on

    self - TimeStamp today
    

    in the workspace pane, the result will be a Duration object that represents the time interval between midnight today and the instant at which you evaluated TimeStamp now and created the TimeStamp object that you are inspecting. You can also try evaluating TimeStamp now - self; this will tell you how long you have spent reading this section of this book!

    In addition to self, all the instance variables of the object are in scope in the workspace pane, so you can use them in expressions or even assign to them. For example, if you evaluate jdn := jdn - 1 in the workspace pane, you will see that the value of the jdn instance variable will indeed change, and the value of TimeStamp now - self will increase by one day.

    You can change instance variables directly by selecting them, replacing the old value in the right-hand pane by a Squeak expression, and accepting. Squeak will evaluate the expression and assign the result to the instance variable.

    There are special variants of the inspector for Dictionaries, OrderedCollections, CompiledMethods and a few other classes that make it easier to examine the contents of these special objects.

    The Object Explorer

    The object explorer is conceptually similar to the inspector, but presents its information in a different way. To see the difference, we’ll explore the same object that we were just inspecting.

    \(\bigstar\) Select self in the inspector’s left-hand pane, and choose explore (I) from the yellow button menu.

    Exploring TimeStamp now.
    Figure \(\PageIndex{2}\): Exploring TimeStamp now.
    Exploring the instance variables.
    Figure \(\PageIndex{3}\): Exploring the instance variables.

    The explorer window looks like Figure \(\PageIndex{2}\). If you click on the small triangle next to root, the view will change to Figure \(\PageIndex{3}\), which shows the instance variables of object that you are exploring. Click on the triangle next to offset, and you will see its instance variables. The explorer is really useful when you need to explore a complex hierarchic structure — hence the name.

    The workspace pane of the object explorer works slightly differently to that of the inspector. self is not bound to the root object, but rather to the object that is currently selected; the instance variables of the selected object are also in scope.

    To see the value of the explorer, let’s use it to explore a deeply-nested structure of objects.

    \(\bigstar\) Open a browser, and blue-click twice on the method pane to bring-up the Morphic halo on the PluggableListMorph that is used to represent the list of messages. Click on the debug handle and select explore morph from the menu that appears. This will open an Explorer on the PluggableListMorph object that represents the method list on the screen. Open the root object (by clicking in its triangle), open its submorphs, and continue exploring the structure of the objects that underlie this Morph, as shown in Figure \(\PageIndex{4}\).

    Exploring a PluggableListMorph.
    Figure \(\PageIndex{4}\): Exploring a PluggableListMorph.

    This page titled 6.4: The Inspector and the Explorer is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.