|
169 | 169 | Finally, \pythonil{print(f"new_var = \{new_var\}." )} then prints \textil{new_var = 14.0.}.% |
170 | 170 | \end{sloppypar}% |
171 | 171 | % |
172 | | -The \acrfull{stdout} of the complete program is given in \cref{exec:variables:assignment}. |
173 | | -For your convenience, we also showed the results when executing the program in \pycharm\ or the \ubuntu\ \pgls{terminal} in \cref{fig:variables:assignment}. |
174 | | -They are obviously identical. |
| 172 | +This first program is stored in a file named~\textil{assignment.py}. |
| 173 | +To execute it, you have two choices: |
| 174 | +You can either open a \pgls{terminal} and enter the folder where the program is stored. |
| 175 | +Then you would execute the command~\bashil{python3 assignment.py} to run the \python\ interpreter in the terminal, as illustrated in \cref{fig:assignmentTerminal}~(for the case of \ubuntu\ \linux). |
| 176 | + |
| 177 | +Alternatively, you can open the program file in \pycharm\ \pgls{ide}, as sketched in \cref{fig:assignmentPyCharm1}. |
| 178 | +You would then right-click on the file \textil{assignment.py} in the project tree view. |
| 179 | +In the popup-menu that opens, you would left-click on \menu{Run `assignment'} as shown in \cref{fig:assignmentPyCharm2}. |
| 180 | +As a shortcut, you can also simply press~\keys{\ctrl+\shift+F10}. |
| 181 | +Either way, \pycharm\ will run the program and the output appears in \cref{fig:assignmentPyCharm}. |
| 182 | +As you see, the full \acrfull{stdout} of the complete program given in \cref{exec:variables:assignment} is identical to what we get from the manual execution in either the \pgls{terminal} or \pycharm. |
175 | 183 |
|
176 | | -Notice that we wrote the names of variables in a certain style, which is somewhat standard in \python\ programming. |
177 | | -For the sake of creating readable code that fits nicely together with code from other projects\dots% |
| 184 | +We are not completely done yet, though. |
| 185 | +Notice that we wrote the names of variables in a certain style, in lowercase letters. |
| 186 | +This is the defactor standard way to name variables and functions in \python\ programming.% |
178 | 187 | % |
179 | 188 | \bestPractice{variableNames}{% |
180 | 189 | Variable names should be lowercase, with words separated by underscores~\cite{PEP8}.% |
181 | 190 | } |
182 | 191 | % |
183 | | -We now have seen some best practices on styling our code, e.g., \cref{bp:variableNames,bp:longstrDoubleQuote,bp:comments}, and many more such best practices will follow. |
184 | | -Before continuing further, let us revisit the deeper meaning behind them. |
| 192 | +This seems like a strange thing to introduce right at the beginning when learning programming. |
| 193 | +Matter of fact, we now have seen some best practices on styling our code, e.g., \cref{bp:variableNames,bp:longstrDoubleQuote,bp:comments}, and many more such best practices will follow. |
| 194 | +Before continuing further, let us therefore revisit the deeper meaning behind them. |
185 | 195 | Why is it important to style our code in a consistent way? |
186 | 196 | Why can't we just write things down in any way that pleases us?% |
187 | 197 | % |
188 | 198 | \bestPractice{codeStyle}{% |
189 | 199 | Regardless which programming language you are using, it is important to write code and scripts in a consistent style, to use a consistent naming scheme for all things that can be named, and to follow the generally established best practices and norms for that language.% |
190 | 200 | }% |
| 201 | +% |
191 | 202 | For many programming languages, there exist comprehensive and clear style guides. |
192 | 203 | Since we usually work collaboratively on larger projects, writing code in a consistent style is very important. |
193 | 204 | Ideally, all collaborators can open a source code file and easily read and understand our code. |
|
0 commit comments