Mercurial > pylearn
annotate doc/v2_planning/coding_style.txt @ 1066:e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
author | Olivier Delalleau <delallea@iro> |
---|---|
date | Fri, 10 Sep 2010 09:53:50 -0400 |
parents | 64720cdca3d3 |
children | 4f287324a5ad |
rev | line source |
---|---|
1009
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
1 Discussion of Coding-Style |
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
2 ========================== |
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
3 |
1017
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
4 Participants |
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
5 ------------ |
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
6 - Dumitru |
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
7 - Fred |
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
8 - David |
1028
c6a74b24330b
coding_style: Olivier D confirmed as leader
Olivier Delalleau <delallea@iro>
parents:
1025
diff
changeset
|
9 - Olivier D [leader] |
1017
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
10 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
11 Existing Python coding style specifications and guidelines |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
12 ---------------------------------------------------------- |
1017
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
13 |
1009
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
14 * http://www.python.org/dev/peps/pep-0008/ |
1060
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
15 * http://www.python.org/dev/peps/pep-0257/ |
1009
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
16 * http://google-styleguide.googlecode.com/svn/trunk/pyguide.html |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
17 * http://www.voidspace.org.uk/python/articles/python_style_guide.shtml |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
18 * http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
19 * http://www.cs.caltech.edu/courses/cs11/material/python/misc/python_style_guide.html |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
20 * http://barry.warsaw.us/software/STYLEGUIDE.txt |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
21 * http://self.maluke.com/style |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
22 * http://chandlerproject.org/Projects/ChandlerCodingStyleGuidelines |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
23 * http://lists.osafoundation.org/pipermail/dev/2003-March/000479.html |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
24 * http://learnpython.pbworks.com/PythonTricks |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
25 * http://eikke.com/how-not-to-write-python-code/ |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
26 * http://jaynes.colorado.edu/PythonGuidelines.html |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
27 * http://docs.djangoproject.com/en/dev/internals/contributing/#coding-style |
1009
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
28 |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
29 We will probably want to take PEP-8 as starting point, and read what other |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
30 people think about it / how other coding guidelines differ from it. |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
31 |
1050 | 32 Dumi: we should also try to find tools that automate these |
33 processes: pylint, pyflakes, pychecker, pythontidy | |
1049
ff9361e39c97
remark on fiding tools
Dumitru Erhan <dumitru.erhan@gmail.com>
parents:
1033
diff
changeset
|
34 |
1060
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
35 OD: Things about PEP 8 I don't like (but it may be just me): |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
36 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
37 * If necessary, you can add an extra pair of parentheses around an |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
38 expression, but sometimes using a backslash looks better. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
39 --> I rarely find that backslash looks better. In most situations you can |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
40 get rid of them. Typically I prefer: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
41 if (cond_1 and |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
42 cond_2 and |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
43 cond_3): |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
44 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
45 if cond_1 and \ |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
46 cond_2 and \ |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
47 cond_3: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
48 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
49 * You should use two spaces after a sentence-ending period. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
50 --> Looks weird to me. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
51 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
52 * Imports should usually be on separate lines |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
53 --> Can be a lot of lines wasted for no obvious benefit. I think this is |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
54 mostly useful when you import different modules from different places, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
55 but I would say that for instance for standard modules it would be |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
56 better to import them all on a single line (doing multiple lines only |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
57 if there are too many of them), e.g. prefer: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
58 import os, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
59 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
60 import os |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
61 import sys |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
62 import time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
63 However, I agree about separating imports between standard lib / 3rd |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
64 party, e.g. prefer: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
65 import os, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
66 import numpy, scipy |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
67 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
68 import numpy, os, scipy, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
69 (Personal note: preferably order imports by alphabetical order, makes |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
70 it easier to quickly see if a specific module is already imported, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
71 and avoids duplicated imports) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
72 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
73 * Missing in PEP 8: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
74 - How to indent multi-line statements? E.g. do we want |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
75 x = my_func(a, b, c, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
76 d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
77 or |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
78 x = my_func(a, b, c, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
79 d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
80 or |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
81 x = my_func( |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
82 a, b, c, d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
83 --> Probably depends on the specific situation, but we could have a |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
84 few typical examples (and the same happens with multi-lines lists) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
85 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
86 * From PEP 257: The BDFL [3] recommends inserting a blank line between the |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
87 last paragraph in a multi-line docstring and its closing quotes, placing |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
88 the closing quotes on a line by themselves. This way, Emacs' |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
89 fill-paragraph command can be used on it. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
90 --> I have nothing against Emacs, but this is ugly! |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
91 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
92 Documentation |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
93 ------------- |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
94 |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
95 How do we write doc? |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
96 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
97 Compatibility with various Python versions |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
98 ------------------------------------------ |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
99 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
100 * Which Python 2.x version do we want to support? |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
101 |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
102 * Is it reasonable to have coding guidelines that would make the code as |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
103 compatible as possible with Python 3? |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
104 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
105 C coding style |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
106 -------------- |
1022 | 107 |
108 We also need a c-style coding style. | |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
109 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
110 Meeting 2010/09/09 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
111 ------------------ |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
112 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
113 * Coding guidelines |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
114 PEP 8 & Google should be a good basis to start with. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
115 Task: Highlight the most important points in them (OD). |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
116 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
117 * Documentation |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
118 Use RST with Sphinx. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
119 Task: Provide specific examples on how to document a class, method, and some |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
120 specific classes like Op (DE). |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
121 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
122 * Python versions to be supported |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
123 Support 2.4 (because some of the clusters are still running 2.4) and write |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
124 code that can be converted to 3.x with 2to3 in a straightforward way. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
125 Task: Write to-do's and to-not-do's to avoid compatibility issues. (OD) |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
126 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
127 * C coding style |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
128 How to write C code (in particular for Numpy / Cuda), and how to mix C and |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
129 Python. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
130 Task: See if there would be a sensible C code style to follow (maybe look how |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
131 Numpy does it), and how projects that mix C and Python deal with it (e.g. use |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
132 separate files, or be able to have mixed syntax highlighting?) (FB) |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
133 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
134 * Program output |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
135 Use the warning and logging modules. Avoid print as much as possible. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
136 Task: Look into these modules to define general guidelines e.g. to decide when |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
137 to use warning instead of logging. (DWF) |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
138 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
139 * Automatized code verification |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
140 Use pychecker & friends to make sure everything is fine. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
141 Task: Look into the various options available (DE) |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
142 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
143 * Tests |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
144 Force people to write tests. Automatic email reminder of code lines not |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
145 covered by tests (see if we can get this from nosetests). Decorator to mark |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
146 some classes / methods as not being tested yet, so as to be able to |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
147 automatically warn the user when he is using untested stuff (and to remind |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
148 ourselves we should add a test). |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
149 Task: See feasibility. (OD) |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
150 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
151 * VIM / Emacs plugins / config files |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
152 To enforce good coding style automatically. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
153 Task: Look for existing options. (FB) |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
154 |
1066
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
155 Suggestion by PV |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
156 ---------------- |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
157 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
158 Have a sample code that showcases everything one should comply to. |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
159 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
160 Some coding guidlines (work-in-progress from OD) |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
161 ------------------------------------------------ |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
162 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
163 * Avoid using lists if all you care about is iterating on something. Using |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
164 lists: |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
165 - uses more memory (and possibly more CPU if the code may break out of |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
166 the iteration) |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
167 - can lead to ugly code when converted to Python 3 with 2to3 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
168 - can have a different behavior if evaluating elements in the list has |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
169 side effects (if you want these side effects, make it explicit by |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
170 assigning the list to some variable before iterating on it) |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
171 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
172 Iterative version List version |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
173 my_dict.iterkeys() my_dict.keys() |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
174 my_dict.itervalues() my_dict.values() |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
175 my_dict.iteritems() my_dict.items() |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
176 itertools.imap map |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
177 itertools.ifilter filter |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
178 itertools.izip zip |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
179 xrange range |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
180 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
181 * Use `in` on container objects instead of using class-specific methods. |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
182 It is easier to read and may allow you to use your code with different |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
183 container types. |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
184 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
185 Yes No |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
186 --- -- |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
187 key in my_dict my_dict.has_key(key) |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
188 sub_string in my_string my_string.find(sub_string) >= 0 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
189 |