Skip to content

Commit

Permalink
Minor typographical updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jatkinson1000 committed Jul 3, 2024
1 parent 50e4972 commit 6539266
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions slides/_naming_for_clarity.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ readability of code massively and can help to make code self documenting.

A few naming tips and conventions:

::: {.incremental}
- The name should show the intention, think about how someone else might read it (this could be future you)
- Use pronounceable names e.g. `mass` not `ms`, `stem` not `stm`
- avoid abbreviations and single letter variable names where possible
Expand All @@ -17,30 +18,31 @@ A few naming tips and conventions:
- Plurals to indicate groups, e.g. a list of dog objects would be `dogs`, not `dog_list`
- Keep it simple and use technical terms where appropriate
- Use explaining variables
:::

:::

## Naming For Clarity
## Naming For Clarity {.smaller}

Some examples:

- Pronounceable names without abbreviations: \
```
ms --> mass
ms --> mass
chclt --> chocolate
stm --> stem
stm --> stem
```
- Naming for the content, not the type: \
```
array --> dogs
age_int --> age
array --> dogs
age_int --> age
country_set --> countries
```
- Naming booleans: \
```
purple --> is_purple
purple --> is_purple
not_plant --> is_plant
sidekick --> has_sidekick
sidekick --> has_sidekick
```


Expand All @@ -49,7 +51,7 @@ sidekick --> has_sidekick

Without explaining variables, it is hard to see what this code is doing:

```
```python
import re

re.match("^\\+?[1-9][0-9]{7,14}$", "+12223334444")
Expand All @@ -59,7 +61,7 @@ re.match("^\\+?[1-9][0-9]{7,14}$", "+12223334444")

It is easier to see the intention. The code is more self-documenting.

```
```python
import re

validate_phone_number_pattern = "^\\+?[1-9][0-9]{7,14}$"
Expand Down Expand Up @@ -89,4 +91,4 @@ Consider the following:
- Keep it simple and use technical terms where appropriate
- Use explaining variables

:::
:::

0 comments on commit 6539266

Please sign in to comment.