Mercurial > pylearn
changeset 1067:4f287324a5ad
Merged
author | Olivier Delalleau <delallea@iro> |
---|---|
date | Fri, 10 Sep 2010 10:00:49 -0400 |
parents | e1aca94f28d8 (diff) 2bbc464d6ed0 (current diff) |
children | 9fe0f0755b03 |
files | doc/v2_planning/coding_style.txt |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/v2_planning/coding_style.txt Thu Sep 09 17:50:50 2010 -0400 +++ b/doc/v2_planning/coding_style.txt Fri Sep 10 10:00:49 2010 -0400 @@ -162,3 +162,39 @@ To enforce good coding style automatically. Task: Look for existing options. (FB) (DWF: I have put some time into this for vim, I will send around my files) + +Suggestion by PV +---------------- + +Have a sample code that showcases everything one should comply to. + +Some coding guidlines (work-in-progress from OD) +------------------------------------------------ + + * Avoid using lists if all you care about is iterating on something. Using + lists: + - uses more memory (and possibly more CPU if the code may break out of + the iteration) + - can lead to ugly code when converted to Python 3 with 2to3 + - can have a different behavior if evaluating elements in the list has + side effects (if you want these side effects, make it explicit by + assigning the list to some variable before iterating on it) + + Iterative version List version + my_dict.iterkeys() my_dict.keys() + my_dict.itervalues() my_dict.values() + my_dict.iteritems() my_dict.items() + itertools.imap map + itertools.ifilter filter + itertools.izip zip + xrange range + + * Use `in` on container objects instead of using class-specific methods. + It is easier to read and may allow you to use your code with different + container types. + + Yes No + --- -- + key in my_dict my_dict.has_key(key) + sub_string in my_string my_string.find(sub_string) >= 0 +