3 A few code guidelines to try to stick to, please comment of none of these make
4 sense, they are pretty basic and mostly apply to old code. However for people
5 who are looking at current code, they make take up bad habits that exist in the
10 Try not to use the functions in the string module, they are deprecated.
12 string.join(<iterable>," ")
14 should be replaced with:
20 string.split(string, delimeter)
22 should be replaced with:
24 string.split(delimeter)
26 Nearly all other methods in string work on string objects and have similar calling
34 should be replaced with:
38 Is not does a reference comparison (address1 = address2 basically) and
39 the == forces a by value compare (with __eq__())
44 Try not to use has_key, you can use
48 instead of if dict.has_key(foo)
50 Also don't do stuff like:
52 if foo in dict and dict[foo]:
54 Generally you can do two things here, if you are messing with defaults..
56 dict.get(foo, some_default)
58 will try to retrieve foo from dict, if there is a KeyError, will insert foo
59 into dict with the value of some_default. This method is preferred in cases where
60 you are messing with defaults:
65 dict[foo] = default_value
67 The get call is nicer (compact) and faster (try,except are slow).
72 Import things one per line
82 When importing from a module, you may import more than 1 thing at a time.
85 from portage.module import foo, bar, baz
87 Multiline imports are ok (for now :))
89 Try to group system and package imports separately.
96 from portage.locks import lockfile
97 from portage.versions import vercmp