10
10
\chapter{Various tips}
12
Due to the \drgeo\ integration in the Pharo Smalltalk environments,
13
there are a few genies we can invoke. Most of them are hidden to the
14
user. It is not we want to restraint its use, instead we don't want to
15
overload the user when discovering \drgeo. As we will show in the
16
following sections, these genies can be invoked from menus, keyboard
17
shortcuts or Smalltalk codes.
12
Due to \drgeo\ integration with the Pharo Smalltalk environment,
13
there are a few genies we can invoke. Most of them are hidden to the
14
user. It is not that we want to restrain their use, but that we
15
don't want to overload the user when discovering \drgeo. As we will
16
show in the following sections, these genies can be invoked from
17
menus, keyboard shortcuts or Smalltalk code.
20
In this section we present a few tools to use when writing Smalltalk
21
script or sketch: the workspace, the debugger, the inspector, etc.
19
\section{Programming} In this section we present a few tools to use
20
when writing Smalltalk scripts or composing sketches, beginning with
21
the workspace, the debugger, and the inspector.
24
24
\drgeoIndex{Workspace}{}{}{}
26
26
\subsection{Workspace}
29
To show it, click on the \drgeo\ environment background then do
29
To show a workspace, click on the \drgeo\ environment background then do
30
30
\drgeoShortcut{Ctrl-k}\footnote{Depending one your system, replace
31
31
\drgeoShortcut{Ctrl} by \drgeoShortcut{Alt}.}.
33
33
\drgeoIndex{Workspace}{Pasting code}{}{}
35
A workspace, at a first glance, is like a text editor. But it is in
36
fact a console to edit Smalltalk code: to write it, to compile and to
37
execute it; it is of course possible to paste code copied somewhere
35
A workspace, at first glance, is like a text editor. But it is in
36
fact a console to edit Smalltalk code: to write it, to compile it,
37
and to execute it. It is of course possible to paste in code copied
40
After its invocation, paste the source code of the Smalltalk sketch
41
bellow\footnote{To paste a text, try with the shortcut
40
After invoking a workspace, paste the source code of the Smalltalk
41
sketch below\footnote{To paste a text, try with the shortcut
42
42
\drgeoShortcut{Ctrl-v} or from its contextual menu (right click).}~:
78
79
\drgeoIndex{Workspace}{Profiling code}{}{}
79
80
\drgeoIndex{Tools}{Profiling}{}{}
81
When executing a complex source code, running it with a profiling
82
When executing complex Smalltalk code, running it with a profiling
82
83
option let you see its bottlenecks. To do so, in the contextual menu
83
84
invoke the command \emph{Profile it}. The source code is executed, the
84
sketch is built then a profile windows informs you about the execution
85
sketch is built, and then a profile window informs you about the execution
85
86
time in different part of the code and the various invoked methods. It
86
is a wonderful to navigate in execution tree of the code and look
87
at the method consuming to much cycle.
87
is a wonderful way to navigate the execution tree of the code and look
88
for methods consuming too many cycles.
90
% Report bug: Cannot resize panes in profiler. They display only two
91
% lines and a fraction each.
89
93
\drgeoFigureSize{\drgeo\ profiling}{fig54}{10}
92
96
\drgeoIndex{Workspace}{Executing step by step}{}{}
94
Last refinement: executing code step by step. It is done through the
95
debugger, in the contextual menu, choose the command \emph{Debug
96
it}. The debugger is invoked on the first line of the source code
97
and it is executed step by step with the button \emph{Over}. In the
98
bottom area of the debugger window, at the right, the local
99
variables. The other buttons allow other refinements in the step by
100
step execution, it is up to you to explore it!
98
Last refinement: stepping through code. This is done through the
99
debugger. Select the code to debug, then in the contextual
100
(right-click) menu, choose the command \emph{Debug it}. The debugger
101
is invoked on the first line of the selected source code, which is
102
executed step by step with the button \emph{Over}, one method call
103
at a time. In the bottom area of the debugger window, at the right,
104
the local variables are shown with type information. Other buttons
105
allow other refinements in step by step execution. You should
106
explore them before looking at Smalltalk documentation.
102
108
\drgeoFigureSize{The \drgeo\ debugger}{fig56}{10}
106
112
\drgeoIndex{Tools}{Debugger}{Breakpoint}{}
107
113
\subsection{Debugger}
109
As shown in the previous section, the debugger lets you execute the
110
code step by step. In the whole \drgeo\ environment you can invoke it
111
any time with the keyboard shortcut \drgeoShortcut{Alt-.}.
113
Moreover, the debugger can be invoked in the source code by adding a
114
line \texttt{self halt.} -- like a breakpoint. In our previous example we modify the source
115
As shown in the previous section, the debugger lets you execute the
116
code step by step. In the \drgeo\ environment you can invoke the
117
debugger on any selected code in a workspace with the keyboard
118
shortcut \drgeoShortcut{Alt-D}.
120
Moreover, the debugger can be invoked in the source code by adding a
121
line \texttt{self halt.} -- like a breakpoint. In our previous
122
example we modify the source code as follow:
133
139
\drgeoIndex{Tools}{Inspector}{}{}
134
140
\subsection{Inspector}
136
With the inspector dialogue, the user consults the attributes of an
137
instance or a variable, it is updated automatically whenever the
138
inspected object change.
142
In the inspector dialogue, the user examines the attributes of an
143
instance or a variable. The information in the view is updated
144
automatically whenever the inspected object changes.
140
In our previous example, suppose we want to see the content of the
141
\texttt{summits} collection. In this case, it is very simple, we add a
142
line of code where we send the message \texttt{inspect} to
146
In our previous example, suppose we want to see the contents of the
147
\texttt{summits} collection. In this case, we very simply add a
148
line of code to send the message \texttt{inspect} to
143
149
\texttt{summits}. The place in the code where we put it is not very
144
important\footnote{For obvious reason, we must avoid to add it in the
145
loop.}, it can be at the beginning or the end because we do not have
150
important\footnote{For obvious reasons, we must avoid adding it in the
151
loop.}. It can be at the beginning or the end because we do not have a
146
152
breakpoint or step by step execution: