|
157 | 157 | Variable names should be lowercase, with words separated by underscores~\cite{PEP8}.% |
158 | 158 | } |
159 | 159 | % |
| 160 | +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. |
| 161 | +Before continuing further, let us revisit the deeper meaning behind them. |
| 162 | +Why is it important to style our code in a consistent way? |
| 163 | +Why can't we just write things down in any way that pleases us?% |
| 164 | +% |
| 165 | +\bestPractice{codeStyle}{% |
| 166 | +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.% |
| 167 | +}% |
| 168 | +For many programming languages, there exist comprehensive and clear style guides. |
| 169 | +Since we usually work collaboratively on larger projects, writing code in a consistent style is very important. |
| 170 | +Ideally, all collaborators can open a source code file and easily read and understand our code. |
| 171 | +If everybody writes code in different styles, maybe using different indentations or different naming conventions, reading code can become harder and even confusing. |
| 172 | +Therefore, style guides often tell us how to name things and how to structure code consistently.% |
| 173 | +% |
| 174 | +\bestPractice{PEP8}{% |
| 175 | +The most important style guide for the \python\ programming language is PEP8:~\citetitle{PEP8}~\cite{PEP8} at \citeurl{PEP8}. % |
| 176 | +\python\ code violating PEP8 is invalid \python code.% |
| 177 | +}% |
| 178 | +% |
160 | 179 | \FloatBarrier% |
161 | 180 | \endhsection% |
162 | 181 | % |
|
241 | 260 | \centering% |
242 | 261 | % |
243 | 262 | \subfloat[][% |
244 | | -The file \textil{pi_liu_hui.py} opened in \pycharm.% |
| 263 | +The file \programUrl{variables:pi_liu_hui} opened in \pycharm.% |
245 | 264 | \label{fig:liuHuiPiPyCharm1}% |
246 | 265 | ]{% |
247 | 266 | \tightbox{\includegraphics[width=0.49\linewidth]{\currentDir/liuHuiPiPyCharm1}}% |
248 | 267 | }% |
249 | 268 | \hfill% |
250 | 269 | % |
251 | 270 | \subfloat[][% |
252 | | -Left-clicking on \menu{Run `pi\_liu\_hui'} in the pop-up menu after right-clicking on \textil{pi_liu_hui.py}, or directly pressing \keys{\ctrl+\shift+F10}, to run the program.% |
| 271 | +Left-clicking on \menu{Run `pi\_liu\_hui'} in the pop-up menu after right-clicking on \programUrl{variables:pi_liu_hui}, or directly pressing \keys{\ctrl+\shift+F10}, to run the program.% |
253 | 272 | \label{fig:liuHuiPiPyCharm2}% |
254 | 273 | ]{% |
255 | 274 | \tightbox{\includegraphics[width=0.49\linewidth]{\currentDir/liuHuiPiPyCharm2}}% |
256 | 275 | }% |
257 | 276 | \\% |
258 | 277 | % |
259 | 278 | \subfloat[][% |
260 | | -The output of the program \textil{pi_liu_hui.py} in \pycharm.% |
| 279 | +The output of the program \programUrl{variables:pi_liu_hui} in \pycharm.% |
261 | 280 | \label{fig:liuHuiPiPyCharm3}% |
262 | 281 | ]{% |
263 | 282 | \tightbox{\includegraphics[width=0.7\linewidth]{\currentDir/liuHuiPiPyCharm3}}% |
264 | 283 | }% |
265 | 284 | \\% |
266 | 285 | % |
267 | 286 | \subfloat[][% |
268 | | -The output of the program \textil{pi_liu_hui.py} in the \ubuntu\ \pgls{terminal} (which you can open via~\ubuntuTerminal).% |
| 287 | +The output of the program \programUrl{variables:pi_liu_hui} in the \ubuntu\ \pgls{terminal} (which you can open via~\ubuntuTerminal).% |
269 | 288 | \label{fig:liuHuiPiTerminal}% |
270 | 289 | ]{% |
271 | 290 | \includegraphics[width=0.7\linewidth]{\currentDir/liuHuiPiTerminal}% |
272 | 291 | }% |
273 | 292 | % |
274 | | -\caption{Running the program \textil{pi_liu_hui.py} from \cref{lst:variables:assignment} in \pycharm~(\cref{fig:assignmentPyCharm1,fig:assignmentPyCharm2,fig:assignmentPyCharm3}) or the \ubuntu\ \pgls{terminal}~(\cref{fig:assignmentTerminal}).}% |
| 293 | +\caption{Running the program \programUrl{variables:pi_liu_hui} from \cref{lst:variables:assignment} in \pycharm~(\cref{fig:assignmentPyCharm1,fig:assignmentPyCharm2,fig:assignmentPyCharm3}) or the \ubuntu\ \pgls{terminal}~(\cref{fig:assignmentTerminal}).}% |
275 | 294 | \label{fig:variables:liuHuiPi}% |
276 | 295 | \end{figure}% |
277 | 296 | % |
|
0 commit comments