Skip to content

Commit 0f6dd9a

Browse files
committed
Added VS Code to coding conventions. Replaced PyCharm references to IDE where needed.
1 parent a4c1b7e commit 0f6dd9a

6 files changed

+42
-44
lines changed

episodes/15-coding-conventions.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,45 @@ Whichever you choose, be consistent throughout the project.
111111

112112
::::::::::::::::::::::::::::::::::::::::::::::::::
113113

114-
PyCharm has built-in support for converting tab indentation to spaces
115-
"under the hood" for Python code in order to conform to PEP 8.
116-
So, you can type a tab character and PyCharm will automatically convert it to 4 spaces.
117-
You can control the amount of spaces that PyCharm uses to replace one tab character
118-
or you can decide to keep the tab character altogether and prevent automatic conversion.
114+
IDEs typically let you control text indentation and whether you would like to use spaces or tab stops.
115+
Such IDEs have built-in support for converting tab indentation to spaces "under the hood" for Python code in order to conform to PEP 8.
116+
So, you can type a tab character and your IDE will automatically convert it to 4 spaces.
117+
You can also control the amount of spaces that the IDE uses to replace one tab character or you can decide to keep the tab character altogether and prevent automatic conversion.
118+
119+
::: group-tab
120+
121+
### PyCharm
122+
123+
By default, PyCharm inserts spaces and uses 4 spaces per tab key.
119124
You can modify these settings in PyCharm's `Settings`\>`Editor`\>`Code Style`\>`Python`.
120125

121-
![](fig/pycharm-indentation.png){alt='Python code indentation settings in PyCharm' .image-with-shadow width="800px"}
126+
![](fig/pycharm-indentation.png){alt='Python code indentation settings in PyCharm' .image-with-shadow width="1000px"}
122127

123128
You can also tell the editor to show non-printable characters
124129
if you are ever unsure what character exactly is being used
125130
by selecting `Settings` > `Editor` > `General` > `Appearance` then checking "Show whitespaces" option.
126131

127132
![](fig/pycharm-whitespace.png){alt='Python code whitespace settings in PyCharm' .image-with-shadow width="800px"}
128133

129-
There are more complex rules on indenting single units of code that continue over several lines,
130-
e.g. function, list or dictionary definitions can all take more than one line.
131-
The preferred way of wrapping such long lines is
132-
by using Python's implied line continuation inside delimiters such as
133-
parentheses (`()`),
134-
brackets (`[]`)
135-
and braces (`{}`),
136-
or a hanging indent.
134+
### VS Code
135+
136+
By default, VS Code inserts spaces and uses 4 spaces per tab key.
137+
You can modify these settings in VS Code's user or workspace settings (`File -> Settings` then search for `tabSize` and enter the value you want).
138+
You also need to make sure `Editor: Detect Indentation` field is checked.
139+
140+
![](fig/vscode-whitespace.png){alt='Python code whitespace settings in VC Code' .image-with-shadow width="1000px"}
141+
142+
If you are editing `settings.json` file manually - these are the 2 properties you need to set:
143+
144+
```yaml
145+
"editor.insertSpaces": true,
146+
"editor.tabSize": 4,
147+
```
148+
149+
:::
150+
151+
There are more complex rules on indenting single units of code that continue over several lines, e.g. function, list or dictionary definitions can all take more than one line.
152+
The preferred way of wrapping such long lines is by using Python's implied line continuation inside delimiters such as parentheses (`()`), brackets (`[]`) and braces (`{}`), or a hanging indent.
137153

138154
```python
139155
# Add an extra level of indentation (extra 4 spaces) to distinguish arguments from the rest of the code that follows
@@ -168,8 +184,7 @@ a_long_list2 = [
168184
]
169185
```
170186

171-
More details on good and bad practices for continuation lines can be found in
172-
[PEP 8 guideline on indentation](https://www.python.org/dev/peps/pep-0008/#indentation).
187+
More details on good and bad practices for continuation lines can be found in [PEP 8 guideline on indentation](https://www.python.org/dev/peps/pep-0008/#indentation).
173188

174189
### Maximum Line Length
175190

@@ -462,8 +477,7 @@ Fix the discovered inconsistencies and commit them to the feature branch.
462477

463478
## Solution
464479

465-
Modify `inflammation-analysis.py` from PyCharm,
466-
which is helpfully marking inconsistencies with coding guidelines by underlying them.
480+
Modify `inflammation-analysis.py` from your IDE, which is helpfully marking inconsistencies with coding guidelines by underlying them.
467481
There are a few things to fix in `inflammation-analysis.py`, for example:
468482

469483
1. Line 30 in `inflammation-analysis.py` is too long and not very readable.
@@ -657,13 +671,10 @@ Functions:
657671
...
658672
```
659673

660-
The docstring for a function or a module
661-
is returned when calling the `help` function and passing its name -
662-
for example from the interactive Python console/terminal available from the command line
663-
or when rendering code documentation online
664-
(e.g. see [Python documentation](https://docs.python.org/3.11/library/index.html)).
665-
PyCharm also displays the docstring for a function/module
666-
in a little help popup window when using tab-completion.
674+
The docstring for a function or a module is returned when calling the `help` function and passing its name -
675+
for example from the interactive Python console/terminal available from the command line or when rendering code documentation online (e.g. see [Python documentation](https://docs.python.org/3.11/library/index.html)).
676+
677+
Your IDE will also display the docstring for a function/module in a little help popup window when using tab-completion or when hovering your mouse over the function/module name.
667678

668679
```python
669680
help(fibonacci)

episodes/17-section1-optional-exercises.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ Some suggestions to try:
4848
- [Sublime Text](https://www.sublimetext.com/)
4949
- [RStudio](https://posit.co/download/rstudio-desktop/)
5050

51-
When compared to PyCharm, the IDEs listed above are advanced source code editors capable of functioning as IDEs.
52-
To function as an IDE, you have to manually install plugins for these tools to obtain more advanced features -
53-
such as support for a specific programming language or unit testing.
51+
The IDEs listed above are advanced source code editors capable of functioning as IDEs by manually installing plugins
52+
and add-ons for these tools to obtain more advanced features - such as support for a specific programming language or unit testing.
5453

5554
What do you prefer, a lot of tooling out of the box or a lightweight editor with optional extensions?
5655

episodes/21-automatically-testing-software.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -454,19 +454,7 @@ for a particular project or team, so you may want to revisit it at a later date.
454454

455455
If you have already installed `pytest` package in your virtual environment,
456456
you can skip this step.
457-
Otherwise, as we have seen, we have a couple of options for installing external libraries:
458-
459-
1. via PyCharm
460-
(see ["Adding an External Library"](13-ides.md) section
461-
in ["Integrated Software Development Environments"](13-ides.md) episode),
462-
or
463-
2. via the command line
464-
(see ["Installing External Libraries in an Environment With `pip`"](12-virtual-environments.md) section
465-
in ["Virtual Environments For Software Development"](12-virtual-environments.md) episode).
466-
467-
To do it via the command line -
468-
exit the Python console first (either with `Ctrl-D` or by typing `exit()`),
469-
then do:
457+
Otherwise, make sure you do it - e.g. via the command line terminal:
470458

471459
```bash
472460
$ python3 -m pip install pytest

episodes/52-assessing-software-suitability-improvement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ and provide feedback.
5151
1. Decide as a team on one of your repositories that will represent your group.
5252
You can do this any way you wish,
5353
but if you are having trouble then a pseudo-random number might help:
54-
`python -c "import numpy as np; print(np.random.randint(low=1, high=<size_group_plus_1>))"`
54+
`python3 -c "import numpy as np; print(np.random.randint(low=1, high=<size_group_plus_1>))"`
5555
2. Add the URL of the repository to
5656
the section of the shared notes labelled 'Decide on your Group's Repository',
5757
next to your team's name.

episodes/fig/vscode-whitespace.png

662 KB
Loading

slides/section_4_collaborative_soft_dev.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ poetry --version # check we have access to the poetry executable
303303
- The current way of sharing our package is:
304304
```bash
305305
git clone <our_repo>
306-
python -m venv venv
306+
python3 -m venv venv
307307
. venv/bin/activate
308308
pip install -r requirements.txt --editable .
309-
python inflammation-analysis.py
309+
python3 inflammation-analysis.py
310310
...
311311
```
312312
- and then there are a bunch of hoops to jump through to make sure import statements work when testing

0 commit comments

Comments
 (0)