Skip to content

Commit 78a3e94

Browse files
committed
Add more content to style guide episode
1 parent 5556d5d commit 78a3e94

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

episodes/style-guide.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Spaces (not tabs) are the preferred indentation method. Use 4 spaces per indenta
1212

1313
```python
1414
# Correct
15+
1516
for x in range(10):
1617
print("x is", i)
1718

@@ -20,6 +21,7 @@ def sayhello():
2021
return x
2122

2223
# Wrong
24+
2325
for x in range(10):
2426
print("x is", x)
2527

@@ -34,12 +36,14 @@ Imports should be on separate lines except when using the from syntax. Imports a
3436

3537
```python
3638
# Correct
39+
3740
import numpy
3841
import polars
3942

4043
from subprocess import Popen, PIPE
4144

4245
# Wrong
46+
4347
import numpy, polars
4448
```
4549

@@ -51,14 +55,17 @@ Imports should be grouped in the order shown below. An empty line should be plac
5155

5256
```python
5357
# Standard library
58+
5459
import os
5560
import math
5661

5762
# Third party
63+
5864
import numpy as np
5965
import matplotlib.pyplot as plt
6066

6167
# Local package
68+
6269
from mypackage.utils import sayhello
6370
```
6471

@@ -82,3 +89,58 @@ def sayhello(x: str) -> str:
8289
return greeting
8390
```
8491

92+
## Naming conventions
93+
94+
Modules should have short lowercase names where underscores can be used to improve readability. Packages should also have short lowercase names but use of underscores is discouraged.
95+
96+
```bash
97+
# Module names
98+
99+
downloader.py
100+
101+
file_downloader.py
102+
```
103+
104+
```python
105+
# Package names
106+
107+
import mypackage
108+
```
109+
110+
Class names should use the capitalized words (or CapWords, CamelCase) convention.
111+
112+
```python
113+
class Downloader:
114+
...
115+
116+
dl = Downloader()
117+
118+
class FileDownloader:
119+
...
120+
121+
file = FileDownloader()
122+
```
123+
124+
Function and variable names should be lowercase with underscores to separate words for readability.
125+
126+
```python
127+
def hello(x):
128+
return f"Hello {x}"
129+
130+
def say_hello(x):
131+
y = f"Hello {x}"
132+
print(y)
133+
```
134+
135+
Constants are usually defined at the module level and written in all capital letters.
136+
137+
```python
138+
# Contents of module named example.py
139+
140+
import numpy as np
141+
import pandas as pd
142+
143+
TOTAL = 89
144+
145+
API_URL = "https://mywebsite/api:8090"
146+
```

0 commit comments

Comments
 (0)