comparison 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
comparison
equal deleted inserted replaced
1062:64720cdca3d3 1066:e1aca94f28d8
150 150
151 * VIM / Emacs plugins / config files 151 * VIM / Emacs plugins / config files
152 To enforce good coding style automatically. 152 To enforce good coding style automatically.
153 Task: Look for existing options. (FB) 153 Task: Look for existing options. (FB)
154 154
155 Suggestion by PV
156 ----------------
157
158 Have a sample code that showcases everything one should comply to.
159
160 Some coding guidlines (work-in-progress from OD)
161 ------------------------------------------------
162
163 * Avoid using lists if all you care about is iterating on something. Using
164 lists:
165 - uses more memory (and possibly more CPU if the code may break out of
166 the iteration)
167 - can lead to ugly code when converted to Python 3 with 2to3
168 - can have a different behavior if evaluating elements in the list has
169 side effects (if you want these side effects, make it explicit by
170 assigning the list to some variable before iterating on it)
171
172 Iterative version List version
173 my_dict.iterkeys() my_dict.keys()
174 my_dict.itervalues() my_dict.values()
175 my_dict.iteritems() my_dict.items()
176 itertools.imap map
177 itertools.ifilter filter
178 itertools.izip zip
179 xrange range
180
181 * Use `in` on container objects instead of using class-specific methods.
182 It is easier to read and may allow you to use your code with different
183 container types.
184
185 Yes No
186 --- --
187 key in my_dict my_dict.has_key(key)
188 sub_string in my_string my_string.find(sub_string) >= 0
189