Skip to content

Commit 48b796f

Browse files
authored
Fixes 1 (ssciwr#6)
* Rename PEP_right_or_wrong to PEP_right_or_wrong.md * Update README.md * Update README.md * Update PEP_right_or_wrong.md * Update PEP_right_or_wrong.md * Update PEP_right_or_wrong.md
1 parent f44cb02 commit 48b796f

File tree

3 files changed

+112
-117
lines changed

3 files changed

+112
-117
lines changed

Material_Part1_PEP/PEP_right_or_wrong

-62
This file was deleted.
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Code alignment
2+
3+
Which of the below alignments are correct?
4+
5+
- [ ] a
6+
```
7+
abs_area = area_A + area_B +
8+
area_C + area_D
9+
```
10+
- [ ] b
11+
```
12+
abs_area = area_A + area_B
13+
+ area_C + area_D
14+
```
15+
16+
- [ ] c
17+
```
18+
result = my_function(area_A, area_B,
19+
area_C, area_D)
20+
```
21+
- [ ] d
22+
```
23+
result = my_function(area_A, area_B,
24+
area_C, area_D)
25+
```
26+
- [ ] e
27+
```
28+
result = my_function(
29+
area_A, area_B,
30+
area_C, area_D
31+
)
32+
```
33+
34+
# Naming conventions
35+
36+
Which of the below naming conventions are correct?
37+
38+
Classes:
39+
- [ ] a `class my-first-analysis:`
40+
- [ ] b `class my_first_analysis:`
41+
- [ ] c `class Myfirstanalysis:`
42+
- [ ] d `class MyFirstAnalysis:`
43+
44+
Functions:
45+
- [ ] a `def calc_area(x):`
46+
- [ ] b `def calc-area(x):`
47+
- [ ] c `def calcarea(x):`
48+
- [ ] d `def Calc_area(x):`
49+
50+
Variables:
51+
- [ ] a `O = abs(x)`
52+
- [ ] b `I = abs(x)`
53+
- [ ] c `l = abs(x)`
54+
- [ ] d `abs_x = abs(x)`
55+
56+
Constants:
57+
- [ ] a `THRESHOLD = 0.1`
58+
- [ ] b `threshold = 0.1`
59+
- [ ] c `Threshold = 0.1`
60+
- [ ] d `T = 0.1`
61+
62+
Other:
63+
- [ ] a ` list = my_areas`
64+
- [ ] b ` list_ = my_areas`
65+
- [ ] c ` __list__ = my_areas`
66+
- [ ] d ` _list = my_areas`
67+
68+
Modules:
69+
70+
Packages:

Material_Part1_PEP/README.md

+42-55
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,31 @@ You can find a list of PEPs [here](https://peps.python.org/).
1212

1313
## PEP 8 summary
1414

15-
1. Line length
15+
1. Line length
1616
Don't write lines that are very long. Reason: Often you would use multiple windows next to each other and that makes it hard to read code (and possibly lead to introduction of bugs).
1717
PEP 8 recommends lines no longer than 79 characters, but 90 is also a good number.
1818

1919
1. Alignment of code
2020
Make use of indentation when using continuation lines:
2121

22-
foo = long_function_name(var_one, var_two,
23-
var_three, var_four)
24-
22+
foo = long_function_name(var_one, var_two,
23+
var_three, var_four)
2524
instead of
2625

2726
foo = long_function_name(var_one, var_two,
2827
var_three, var_four)
29-
3028
You may also use hanging indents
3129

3230
foo = long_function_name(
3331
var_one, var_two,
3432
var_three, var_four)
35-
3633
1. Break line before binary operator
3734

3835
income = (gross_wages
3936
+ taxable_interest
4037
+ (dividends - qualified_dividends)
4138
- ira_deduction
4239
- student_loan_interest)
43-
4440
instead of
4541

4642
income = (gross_wages +
@@ -50,69 +46,61 @@ Make use of indentation when using continuation lines:
5046
student_loan_interest)
5147

5248
1. Blank lines:
53-
- two blank lines after `import` statements
54-
- two blank lines between functions and classes
55-
- one blank line between methods of classes
49+
- two blank lines after `import` statements
50+
- two blank lines between functions and classes
51+
- one blank line between methods of classes
5652

57-
import os
53+
import os
5854

5955

60-
def greeting():
61-
print("Hello world!")
56+
def greeting():
57+
print("Hello world!")
6258

6359

64-
def goodbye():
65-
print("See ya!")
66-
67-
instead of
60+
def goodbye():
61+
print("See ya!")
62+
instead of
6863

69-
import os
70-
71-
def greeting():
72-
print("Hello world!")
64+
import os
7365

74-
def goodbye():
75-
print("See ya!")
66+
def greeting():
67+
print("Hello world!")
7668

77-
and
69+
def goodbye():
70+
print("See ya!")
71+
and
7872

79-
def something():
80-
pass
73+
def something():
74+
pass
8175

8276

83-
class MyClass:
77+
class MyClass:
8478

85-
def my_method():
86-
pass
87-
88-
def some_other():
89-
pass
79+
def my_method():
80+
pass
9081

82+
def some_other():
83+
pass
9184
instead of
9285

93-
def something():
94-
pass
95-
96-
class MyClass:
97-
def my_method():
86+
def something():
9887
pass
99-
def some_other():
100-
pass
101-
10288

89+
class MyClass:
90+
def my_method():
91+
pass
92+
def some_other():
93+
pass
10394
1. Encoding: The source file should always use UTF-8 encoding, and preferably without non-ASCII characters. It also makes your code more general if you use English words for identifiers (function names etc.).
104-
10595
1. Imports should be on separate lines:
10696

10797
import os
10898
import sys
109-
11099
and not
111100

112101
import os, sys
113102

114103
1. String quotes: Do either use `'` or `"` throughout your project - do not mix. For triple-quoted strings, always use `"`, so `"""` instead of `'''`.
115-
116104
1. Whitespaces:
117105
- no whitespace in parantheses - do `{item: 1}`, don't ```{ item: 1 }```
118106
- whitespace after comma - do `a, b`, don't `a,b`, but not if followed by a parenthesis - do `(a, b,)` don't `(a, b, )`
@@ -122,19 +110,18 @@ Make use of indentation when using continuation lines:
122110
1. Keep comments up-to-date when changing the code. Comments should be complete sentences with a capitalized first word (unless it is an identifier). Use English language preferably.
123111
1. Include docstrings - see below (PEP 257).
124112
1. Naming conventions:
125-
- package and module names: short all-lowercase, preferably no underscores (do `analysis.py`, don't `Analysis.py`; do `mypackage`, don't `my_package`)
126-
- class names: use CamelCase (do `MyClass`, don't `myclass`, `Myclass`, `MYCLASS`)
127-
- functions and variable names: use lowercase with underscore to increase readibility (do `my_function()`, don't `myfunction()`, `MyFunction()`; do `accuracy_param`, don't `accuracyparam`, `accuracy_PARAM`)
128-
- constants: all capital with separating underscore (do `MIN_THRESHOLD`, don't `Min_Threshold`)
129-
- never use `l, O, I` letter names because of their similarity with `1` and `0`
130-
113+
- package and module names: short all-lowercase, preferably no underscores (do `analysis.py`, don't `Analysis.py`; do `mypackage`, don't `my_package`)
114+
- class names: use CamelCase (do `MyClass`, don't `myclass`, `Myclass`, `MYCLASS`)
115+
- functions and variable names: use lowercase with underscore to increase readibility (do `my_function()`, don't `myfunction()`, `MyFunction()`; do `accuracy_param`, don't `accuracyparam`, `accuracy_PARAM`)
116+
- constants: all capital with separating underscore (do `MIN_THRESHOLD`, don't `Min_Threshold`)
117+
- never use `l, O, I` letter names because of their similarity with `1` and `0`
131118
1. Underscores:
132-
- avoid name clashes using a trailing underscore or synonym (`class_`)
133-
- single leading underscore for methods that should only be used "internally" (should not be made available to the package or class interface)
134-
- use two leading underscores to invoke name mangling for attributes that should not be used in subclasses of the parent class (`__only_parent`)
135-
- double leading and trailing underscores for "magic" objects (dunder methods) - `__init__`, `__str__`
119+
- avoid name clashes using a trailing underscore or synonym (`class_`)
120+
- single leading underscore for methods that should only be used "internally" (should not be made available to the package or class interface)
121+
- use two leading underscores to invoke name mangling for attributes that should not be used in subclasses of the parent class (`__only_parent`)
122+
- double leading and trailing underscores for "magic" objects (dunder methods) - `__init__`, `__str__`
136123

137-
**Task 1: Let's take a look at some [examples](./PEP_right_or_wrong).**
124+
**Task 1: Let's take a look at some [examples](./PEP_right_or_wrong.md).**
138125

139126
**Task 2: Work through the examples [in this folder](.). Correct the issues and (i) stage, commit and push the changes to your fork of the course repo, then open a pull request with respect to the original repository - then I can see the changes. (ii) Send me your changed files via email.**
140127

@@ -146,4 +133,4 @@ Make use of indentation when using continuation lines:
146133

147134
## PEP 20
148135

149-
The Zen of Python. Type `import this` in your Python console.
136+
The Zen of Python. Type `import this` in your Python console.

0 commit comments

Comments
 (0)