Mercurial > pylearn
annotate doc/v2_planning/coding_style.txt @ 1096:2bbc294fa5ac
requirements: Added a use case
author | Olivier Delalleau <delallea@iro> |
---|---|
date | Mon, 13 Sep 2010 09:38:26 -0400 |
parents | d422f726c156 |
children | 56c5f0990869 |
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 |
1072 | 11 |
12 | |
13 Fred: This is a refactored thing from James email of what we should put in message | |
14 that we send to the user: | |
15 1) Hint where in the code this log come from. | |
16 2) Hint how to hide this message? or we should this into documentation. | |
17 3) Tell explicitly if the user can ignore it and the consequence. | |
18 | |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
19 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
|
20 ---------------------------------------------------------- |
1017
af80b7d182af
coding_style: Added list of participants in the committee
Olivier Delalleau <delallea@iro>
parents:
1009
diff
changeset
|
21 |
1072 | 22 * http://www.python.org/dev/peps/pep-0008/ Style Guide for Python Code |
23 * http://www.python.org/dev/peps/pep-0257/ Docstring Conventions | |
24 * http://google-styleguide.googlecode.com/svn/trunk/pyguide.html Google Python Style Guide | |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
25 * 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
|
26 * 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
|
27 * 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
|
28 * http://barry.warsaw.us/software/STYLEGUIDE.txt |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
29 * http://self.maluke.com/style |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
30 * http://chandlerproject.org/Projects/ChandlerCodingStyleGuidelines |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
31 * 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
|
32 * http://learnpython.pbworks.com/PythonTricks |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
33 * 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
|
34 * http://jaynes.colorado.edu/PythonGuidelines.html |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
35 * http://docs.djangoproject.com/en/dev/internals/contributing/#coding-style |
1063
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
36 * http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines |
1009
dc5185cca21e
Added files for Coding Style and Optimization committees
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
37 |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
38 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
|
39 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
|
40 |
1050 | 41 Dumi: we should also try to find tools that automate these |
42 processes: pylint, pyflakes, pychecker, pythontidy | |
1049
ff9361e39c97
remark on fiding tools
Dumitru Erhan <dumitru.erhan@gmail.com>
parents:
1033
diff
changeset
|
43 |
1060
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
44 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
|
45 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
46 * 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
|
47 expression, but sometimes using a backslash looks better. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
48 --> 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
|
49 get rid of them. Typically I prefer: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
50 if (cond_1 and |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
51 cond_2 and |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
52 cond_3): |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
53 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
54 if cond_1 and \ |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
55 cond_2 and \ |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
56 cond_3: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
57 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
58 * 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
|
59 --> Looks weird to me. |
1063
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
60 (DWF: This is an old convention from the typewriter era. It has more |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
61 or less been wiped out by HTML's convention of ignoring extra |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
62 whitespace: see http://en.wikipedia.org/wiki/Sentence_spacing for |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
63 more detail. I think it's okay to drop this convention in source code.) |
1060
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
64 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
65 * Imports should usually be on separate lines |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
66 --> 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 import os, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
72 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
73 import os |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
74 import sys |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
75 import time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
76 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
|
77 party, e.g. prefer: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
78 import os, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
79 import numpy, scipy |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
80 to |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
81 import numpy, os, scipy, sys, time |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
82 (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
|
83 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
|
84 and avoids duplicated imports) |
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 * Missing in PEP 8: |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
87 - 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
|
88 x = my_func(a, b, c, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
89 d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
90 or |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
91 x = my_func(a, b, c, |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
92 d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
93 or |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
94 x = my_func( |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
95 a, b, c, d, e, f) |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
96 --> 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
|
97 few typical examples (and the same happens with multi-lines lists) |
1072 | 98 (Fred: I would do 2 or 3, but not 1. I find it more redable when the |
99 indent is broken after a paranthesis then at any point. | |
1075
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
100 OD: After thinking about it, I agreee as well. My recommendation would |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
101 be to go with 2 when it can fit on two lines, and 3 otherwise. Same |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
102 with lists. |
1060
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
103 |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
104 * 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
|
105 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
|
106 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
|
107 fill-paragraph command can be used on it. |
b4ccf6b43f27
coding_style: Added some comments about PEP8
Olivier Delalleau <delallea@iro>
parents:
1050
diff
changeset
|
108 --> 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
|
109 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
110 Documentation |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
111 ------------- |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
112 |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
113 How do we write doc? |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
114 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
115 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
|
116 ------------------------------------------ |
1020
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
117 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
118 * 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
|
119 |
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
120 * 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
|
121 compatible as possible with Python 3? |
53f6eb80abf1
coding_style: More links and sections to discuss
Olivier Delalleau <delallea@iro>
parents:
1017
diff
changeset
|
122 |
1025
1c96e7ad95c3
coding_style: Added discussion point about backward compatibility with Python 2.x versions
Olivier Delalleau <delallea@iro>
parents:
1022
diff
changeset
|
123 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
|
124 -------------- |
1022 | 125 |
126 We also need a c-style coding style. | |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
127 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
128 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
|
129 ------------------ |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
130 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
131 * Coding guidelines |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
132 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
|
133 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
|
134 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
135 * Documentation |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
136 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
|
137 Task: Provide specific examples on how to document a class, method, and some |
1072 | 138 specific classes like Op (DE). Modify the theano documentation to include that. |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
139 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
140 * 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
|
141 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
|
142 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
|
143 Task: Write to-do's and to-not-do's to avoid compatibility issues. (OD) |
1063
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
144 (DWF: Pauli Virtanen and others have put together extensive |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
145 documentation in the process of porting NumPy to Py3K, see his notes at |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
146 http://projects.scipy.org/numpy/browser/trunk/doc/Py3K.txt -- this is |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
147 the most complete resource for complicated combinations of Python and C). |
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
148 |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
149 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
150 * C coding style |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
151 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
|
152 Python. |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
157 * Program output |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
158 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
|
159 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
|
160 to use warning instead of logging. (DWF) |
1033
f1e0a180574a
coding_style: Added meeting date & time
Olivier Delalleau <delallea@iro>
parents:
1028
diff
changeset
|
161 |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
162 * Automatized code verification |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
163 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
|
164 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
|
165 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
166 * Tests |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 |
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
174 * 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
|
175 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
|
176 Task: Look for existing options. (FB) |
1063
074901ccf7b6
Some additional notes on some of the tasks and points from the meeting.
wardefar@grincheux.iro.umontreal.ca
parents:
1062
diff
changeset
|
177 (DWF: I have put some time into this for vim, I will send around my files) |
1062
64720cdca3d3
coding_style: Notes from today's meeting and tasks for next week
Olivier Delalleau <delallea@iro>
parents:
1060
diff
changeset
|
178 |
1066
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
179 Suggestion by PV |
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 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
182 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
|
183 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
184 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
|
185 ------------------------------------------------ |
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 * 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
|
188 lists: |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
189 - 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
|
190 the iteration) |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
191 - 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
|
192 - 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
|
193 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
|
194 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
|
195 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
196 Iterative version List version |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 itertools.imap map |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
201 itertools.ifilter filter |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
202 itertools.izip zip |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
203 xrange range |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
204 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
205 * 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
|
206 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
|
207 container types. |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
208 |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
209 Yes No |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
210 --- -- |
e1aca94f28d8
coding_style: Added suggestion from PV, and a few coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1062
diff
changeset
|
211 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
|
212 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
|
213 |
1070
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
214 * (Point to debate) Avoid contractions in code comments (particularly in |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
215 documentation): "We do not add blue to red because it does not look |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
216 good" rather than "We don't add blue to red because it doesn't look |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
217 good". I mostly find it to be cleaner (been used to it while writing |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
218 scientific articles too). |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
219 |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
220 * (Point to debate) Imperative vs. third-person comments. I am used to the |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
221 imperative form and like it better only because it typically saves one |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
222 letter (the 's'): "Return the sum of elements in x" rather than |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
223 "Returns the sum of elements in x". |
79eb0016f333
coding_style: Added a couple points to debate
Olivier Delalleau <delallea@iro>
parents:
1067
diff
changeset
|
224 |
1073
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
225 * (Point to debate) I like always doing the following when subclassing |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
226 a class A: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
227 class B(A): |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
228 def __init__(self, b_arg_1, b_arg_2, **kw): |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
229 super(B, self).__init__(**kw) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
230 ... |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
231 The point here is that the constructor always allow for extra keyword |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
232 arguments (except for the class at the very top of the hierarchy), which |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
233 are automatically passed to the parent class. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
234 Pros: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
235 - You do not need to repeat the parent class arguments whenever you |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
236 write a new subclass. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
237 - Whenever you add an argument to the parent class, all child classes |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
238 can benefit from it without modifying their code. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
239 Cons: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
240 - One needs to look at the parent classes to see what these arguments |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
241 are. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
242 - You cannot use a **kw argument in your constructor for your own |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
243 selfish purpose. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
244 - I have no clue whether one could do this with multiple inheritance. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
245 - More? |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
246 Question: Should we encourage this in Pylearn? |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
247 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
248 * Generally prefer list comprehensions to map / filter, as the former are |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
249 easier to read. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
250 Yes: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
251 non_comments = [line.strip() for line in my_file.readlines() |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
252 if not line.startswith('#')] |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
253 No: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
254 non_comments = map(str.strip, |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
255 filter(lambda line: not line.startswith('#'), |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
256 my_file.readlines())) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
257 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
258 * Use the `key` argument instead of `cmp` when sorting (for Python 3 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
259 compatibility). |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
260 Yes: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
261 my_list.sort(key=abs) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
262 No: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
263 my_list.sort(cmp=lambda x, y: cmp(abs(x), abs(y))) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
264 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
265 * Use // for integer division (for readability and Python 3 compatibility). |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
266 Yes: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
267 n_samples_per_split = n_samples // n_splits |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
268 No: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
269 n_samples_per_split = n_samples / n_splits |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
270 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
271 * Only use ASCII characters in code files. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
272 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
273 * Code indent must be done with four blank characters (not with tabs). |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
274 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
275 * Whenever you read / write binary files, specify it in the mode ('rb' for |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
276 reading, 'wb' for writing). This is important for cross-platform and |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
277 Python 3 compatibility (e.g. when pickling / unpickling objects). |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
278 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
279 * Avoid tuple parameter unpacking to avoid very ugly code when converting |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
280 to Python 3. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
281 Yes: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
282 def f(x, y_z): |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
283 y, z = y_z |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
284 No: |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
285 def f(x, (y, z)) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
286 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
287 * Only use cPickle, not pickle. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
288 |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
289 * Always raise exception with |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
290 raise MyException(args) |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
291 where MyException inherits from Exception. |
3e7978201ffc
coding_style: Some more python coding guidelines
Olivier Delalleau <delallea@iro>
parents:
1070
diff
changeset
|
292 |
1075
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
293 Mercurial commits |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
294 ----------------- |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
295 |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
296 * How to write good commit messages? |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
297 * Standardize the merge commit text (what is the message from fetch?) |
d422f726c156
coding_style: Discussion and one more point to think about
Olivier Delalleau <delallea@iro>
parents:
1074
diff
changeset
|
298 |