|
8 | 8 | \centering% |
9 | 9 | % |
10 | 10 | \subfloat[][% |
11 | | -We run the program \textil{assignment_wrong.py} given in \cref{lst:variables:assignment_wrong} in the \pycharm\ \pgls{IDE} by clicking on the \pycharmRun\ button or by pressing~\keys{\shift+F10}.% |
| 11 | +We run the program \textil{assignment_wrong.py} given in \cref{lst:variables:assignment_wrong} in the \pycharm\ \pgls{ide} by clicking on the \pycharmRun\ button or by pressing~\keys{\shift+F10}.% |
12 | 12 | \label{fig:errorsInIde01runProgram}% |
13 | 13 | ]{\tightbox{\includegraphics[width=0.9\linewidth]{\currentDir/errorsInIde01runProgram}}}% |
14 | 14 | % |
|
32 | 32 | \label{fig:errorsInIde03underlined}% |
33 | 33 | ]{\tightbox{\includegraphics[width=0.9\linewidth]{\currentDir/errorsInIde03underlined}}}% |
34 | 34 | % |
35 | | -\caption{How the \pgls{IDE} can help us finding errors.}% |
| 35 | +\caption{How the \pgls{ide} can help us finding errors.}% |
36 | 36 | \label{fig:errorsInIdeA}% |
37 | 37 | \end{figure}% |
38 | 38 | % |
|
41 | 41 | \centering% |
42 | 42 | % |
43 | 43 | \subfloat[][% |
44 | | -The \pgls{IDE} also informs us that something is wrong by displaying the small red~\pycharmErrorsSymbol~icon in the top-right corner. % |
| 44 | +The \pgls{ide} also informs us that something is wrong by displaying the small red~\pycharmErrorsSymbol~icon in the top-right corner. % |
45 | 45 | This is the \emph{third} way to find errors. % |
46 | 46 | We click on it\dots% |
47 | 47 | \label{fig:errorsInIde04errors}% |
|
64 | 64 | \label{fig:errorsInIde06errorsListToLine}% |
65 | 65 | ]{\tightbox{\includegraphics[width=0.9\linewidth]{\currentDir/errorsInIde06errorsListToLine}}}% |
66 | 66 | % |
67 | | -\caption{How the \pgls{IDE} can help us finding errors.}% |
| 67 | +\caption{How the \pgls{ide} can help us finding errors.}% |
68 | 68 | \label{fig:errorsInIdeB}% |
69 | 69 | \end{figure}% |
70 | 70 | % |
|
73 | 73 | \centering% |
74 | 74 | % |
75 | 75 | \subfloat[][% |
76 | | -The \emph{fourth} way in which the \pycharm\ \pgls{IDE} can help us to discover errors are small red marks at the right-hand side. % |
| 76 | +The \emph{fourth} way in which the \pycharm\ \pgls{ide} can help us to discover errors are small red marks at the right-hand side. % |
77 | 77 | Holding the mouse cursor over these lines will open a small view with the suggested error message.% |
78 | 78 | \label{fig:errorsInIde07errorMark}% |
79 | 79 | ]{\tightbox{\includegraphics[width=0.9\linewidth]{\currentDir/errorsInIde07errorMark}}}% |
|
92 | 92 | \label{fig:errorsInIde09sidebarToView}% |
93 | 93 | ]{\tightbox{\includegraphics[width=0.9\linewidth]{\currentDir/errorsInIde09sidebarToView}}}% |
94 | 94 | % |
95 | | -\caption{How the \pgls{IDE} can help us finding errors.}% |
| 95 | +\caption{How the \pgls{ide} can help us finding errors.}% |
96 | 96 | \label{fig:errorsInIdeC}% |
97 | 97 | \end{figure}% |
98 | 98 | % |
99 | | -Before we depart from \pycharm\ screenshots, however, we will visit one absolutely crucial functionality that modern \pglspl{IDE} provide: |
| 99 | +Before we depart from \pycharm\ screenshots, however, we will visit one absolutely crucial functionality that modern \pglspl{ide} provide: |
100 | 100 | They help us to find errors in the code. |
101 | 101 | Errors are common. |
102 | 102 | They happen all the time. |
103 | 103 | Every programmer sometimes makes a typo, accidentally switches the order of parameters of a function, stores a \pythonil{float} in an \pythonil{int} variable, and so on. |
104 | 104 | Some errors are obvious and easy to fix. |
105 | 105 | Some require more serious debugging (see \cref{sec:dunder:debugging}). |
106 | | -In many cases, however, our \pgls{IDE} can already show us what and where the mistake happened. |
| 106 | +In many cases, however, our \pgls{ide} can already show us what and where the mistake happened. |
107 | 107 |
|
108 | 108 | In \cref{lst:variables:assignment_wrong}, we prepared program \textil{assignment_wrong.py}, a variant of \textil{assignment.py}~(\cref{lst:variables:assignment}) with an error. |
109 | 109 | For the sake of the example, let us assume that the programmer made a type in line~12 of the program: |
110 | 110 | They misspelled \pythonil{int_var} and \pythonil{intvar}. |
111 | 111 | Executing the program with the error leads to the output given in \cref{exec:variables:assignment_wrong}. |
112 | 112 |
|
113 | 113 | The questions now are: |
114 | | -How can we see this same error in our \pycharm\ \pgls{IDE}? |
| 114 | +How can we see this same error in our \pycharm\ \pgls{ide}? |
115 | 115 | Could we have found this error even without executing the program? |
116 | 116 |
|
117 | | -To answer these questions, we open the program \textil{assignment_wrong.py} given in \cref{lst:variables:assignment_wrong} in the \pycharm\ \pgls{IDE}. |
| 117 | +To answer these questions, we open the program \textil{assignment_wrong.py} given in \cref{lst:variables:assignment_wrong} in the \pycharm\ \pgls{ide}. |
118 | 118 | We execute this program manually by clicking on the \pycharmRun\ button or by pressing~\keys{\shift+F10} in \cref{fig:errorsInIde01runProgram}. |
119 | 119 | As you can see, the output in the run window is the same as given in \cref{exec:variables:assignment_wrong}~(\cref{fig:errorsInIde02exception}). |
120 | 120 | Reading this output is the \emph{first} way to find out what went wrong. |
|
141 | 141 | This should have told us already that something is fishy without the need to even run the program in the first place.% |
142 | 142 | % |
143 | 143 | \bestPractice{redUnderline}{% |
144 | | -When writing code, we should always check whether the \pgls{IDE} notifies us about potential errors. % |
| 144 | +When writing code, we should always check whether the \pgls{ide} notifies us about potential errors. % |
145 | 145 | In the case of \pycharm, these are often underlined in red or yellow color. % |
146 | 146 | We should always check all such marks!% |
147 | 147 | }% |
148 | 148 | % |
149 | | -So we already know two ways in which we can find errors in our code with the help of our \pgls{IDE}. |
| 149 | +So we already know two ways in which we can find errors in our code with the help of our \pgls{ide}. |
150 | 150 | But there are even more ways. |
151 | 151 |
|
152 | | -The \pgls{IDE} also informs us that something is wrong by displaying the small red~\pycharmErrorsSymbol~icon in the top-right corner, as shown in \cref{fig:errorsInIde04errors}. |
| 152 | +The \pgls{ide} also informs us that something is wrong by displaying the small red~\pycharmErrorsSymbol~icon in the top-right corner, as shown in \cref{fig:errorsInIde04errors}. |
153 | 153 | Clicking on this symbol is the third way to find errors. |
154 | 154 | This will take us to the list of potential errors that it has detected in \cref{fig:errorsInIde05errorsList}. |
155 | 155 | Here, \pycharm\ tells us that there is an \emph{\inQuotes{Unresolved reference \inSQuotes{intvar}}} at line~12 of the file. |
156 | 156 | We can also click on that note, and it takes us again to the dodgy line in \cref{fig:errorsInIde06errorsListToLine} |
157 | 157 |
|
158 | | -The fourth method in which the \pycharm\ \pgls{IDE} can help us to discover errors are small red marks at the right-hand side of our editor window, shown in \cref{fig:errorsInIde07errorMark}. |
| 158 | +The fourth method in which the \pycharm\ \pgls{ide} can help us to discover errors are small red marks at the right-hand side of our editor window, shown in \cref{fig:errorsInIde07errorMark}. |
159 | 159 | Holding the mouse cursor over these lines will open a small view with the suggested error message. |
160 | 160 |
|
161 | 161 | The fifth way to get a list of potential errors in \pycharm\ is to click on the \pycharmErrorsButton~button in the side menu on the left-hand side or to press~\keys{\Alt+6}, as illustrated in \cref{fig:errorsInIde08sidebar}. |
162 | 162 | This again takes us to the list of potential errors in \cref{fig:errorsInIde09sidebarToView}. |
163 | 163 | % |
164 | 164 | \usefulTool{ideForErrors}{% |
165 | | -The \pgls{IDE} and the error messages (\pythonilIdx{Exception} \pglspl{stackTrace}) are your most important tools to find errors. % |
| 165 | +The \pgls{ide} and the error messages (\pythonilIdx{Exception} \pglspl{stackTrace}) are your most important tools to find errors. % |
166 | 166 | Read error messages. % |
167 | | -If your \pgls{IDE} -- regardless whether it is \pycharm\ or something else -- annotates your code with some marks, then you should check every single one of them.% |
| 167 | +If your \pgls{ide} -- regardless whether it is \pycharm\ or something else -- annotates your code with some marks, then you should check every single one of them.% |
168 | 168 | }% |
169 | 169 | % |
170 | 170 | These tools make it much much easier to find errors. |
171 | 171 | You can guess the importance of such features also by how many different ways \pycharm\ implements to get you to click and investigate its list of proposed errors and warnings. |
172 | | -As mentioned in \cref{bp:readErrorMessage,bp:redUnderline}, using the \pgls{IDE} features for error discovery and detection is incredibly important. |
| 172 | +As mentioned in \cref{bp:readErrorMessage,bp:redUnderline}, using the \pgls{ide} features for error discovery and detection is incredibly important. |
173 | 173 | Even if your program executes as expected, there still might be hidden errors in the code. |
174 | 174 | Sometimes, you cannot easily tell whether the output of a program is correct. |
175 | 175 | And the output you see might actually be wrong. |
176 | 176 | Sometimes, there might be some incorrect instructions in your program that just weren't used in your last execution. |
177 | 177 | So even correct program output does not guarantee that the program itself is correct. |
178 | | -Therefore, always checking each and every piece of code that your \pgls{IDE} marks as dodgy is very important. |
| 178 | +Therefore, always checking each and every piece of code that your \pgls{ide} marks as dodgy is very important. |
179 | 179 | Make sure that you full understand all error and warning messages. |
180 | 180 |
|
181 | 181 | Warnings can be important, too. |
|
0 commit comments