[sugar] Python coding conventions
Ian Bicking
ianb
Mon Oct 2 11:19:57 EDT 2006
Marco Pesenti Gritti wrote:
> I tried to use lower case names for modules and it works better. Unless
> Dan disagree I think we should go with this style for modules. Ian, it
> would be great if you could come up with a simple code style document.
PEP 8 goes over most all of these things:
http://www.python.org/dev/peps/pep-0008/
Module names and tabs were the only things I noticed that didn't conform
with PEP 8. Well, the use of getter functions vs properties is an
outstanding issue. There's lots of getter/setter functions in the
current codebase. For a simple getter you can do:
class PresenceService(gobject.GObject):
@property
def services(self):
resp = self._ps.getServices()
servs = []
for item in resp:
servs.append(self._new_object(item))
return servs
And then you'll get a read-only property of the services. One possible
confusion with using properties is that it won't be clear when an
attribute is more likely to fail or stall (which could happen anytime
you access another process over dbus), and it won't be clear when the
return value is mutable. In this case the value is mutable, but to no
effect -- the list is merely constructed anew each time. Using a method
or a property here is just a hint at what it is and how it works, but in
this case a method might be the best hint.
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Sugar-devel
mailing list