-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHESS_CODING_STYLE
163 lines (104 loc) · 4.19 KB
/
CHESS_CODING_STYLE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
Chess Coding Style
Imported mainly from PEP8 and Google Coding Style.
-------------------------------------------------------------------------------
1-Identation
Identation must be 4-spaces only.
2-Maximum line length
Limit all lines to a maximum of 79 characters. The preferred way of wrapping
long lines is by using Python's implied line continuation inside parentheses,
brackets and braces. Long lines can be broken over multiple lines by wrapping
expressions in parentheses. The preferred place to break around a binary
operator is after the operator, not before it. Example:
if width == 0 and height == 0 and (color == 'red' or
emphasis is None):
3-Space policy
Avoid extraneous whitespace in the following situations:
Immediately inside parentheses, brackets or braces.
Yes: spam(ham[1], {eggs: 2})
No: spam( ham[ 1 ], { eggs: 2 } )
Immediately before a comma, semicolon, or colon:
Yes: if x == 4: print x, y; x, y = y, x
No: if x == 4 : print x , y ; x , y = y , x
Immediately before the open parenthesis that starts the argument list of a
function call:
Yes: spam(1)
No: spam (1)
Immediately before the open parenthesis that starts an indexing or slicing:
Yes: dict['key'] = list[index]
No: dict ['key'] = list [index]
More than one space around an assignment (or other) operator to align it with
another.
Yes:
x = 1
y = 2
long_variable = 3
No:
x = 1
y = 2
long_variable = 3
Always surround these binary operators with a single space on either side:
assignment (=), augmented assignment (+=, -= etc.),
comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
Booleans (and, or, not).
If operators with different priorities are used, consider adding whitespace
around the operators with the lowest priority(ies). Never use more than one
space, and always have the same amount of whitespace on both sides of a binary
operator.
Yes:
i = i + 1
submitted += 1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)
No:
i=i+1
submitted +=1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
Don't use spaces around the = sign when used to indicate a keyword argument or
a default parameter value.
Yes:
def complex(real, imag=0.0):
return magic(r=real, i=imag)
No:
def complex(real, imag = 0.0):
return magic(r = real, i = imag)
4-Blank Line
Use blank lines to indicate logical sections.
5-Import
Imports must be in seperated lines. Imports are always put at the top of the
file, just after any module comments and docstrings, and before module globals
and constants.
Imports should be grouped in the following order:
standard library imports
related third party imports
local application/library specific imports
You should put a blank line between each group of imports.
6-Comments
Block comments generally apply to some (or all) code that follows them, and are
indented to the same level as that code. Each line of a block comment starts
with a # and a single space (unless it is indented text inside the comment).
Paragraphs inside a block comment are separated by a line containing a single #.
Inline comments should be separated by at least two spaces from the statement.
They should start with a # and a single space. Inline comments are unnecessary
and in fact distracting if they state the obvious.
7-Docstrings
Write docstrings for all public modules, functions, classes, and methods.
Docstrings are not necessary for non-public methods, but you should have a
comment that describes what the method does. This comment should appear after
the def line.
The """ that ends a multiline docstring should be on a line by itself.
Example:
def my_function():
"""Return the value 42
More detailed explanation about my_function.
Bla bla bla...
"""
return 42
8-Naming
Use the following convention:
module_name, package_name, ClassName, method_name, ExceptionName,
function_name, GLOBAL_CONSTANT_NAME, global_var_name, instance_var_name,
function_parameter_name, local_var_name
-------------------------------------------------------------------------------