[Zope3-Users] Buddydemo / coding style question

Fred Drake fdrake at gmail.com
Thu Nov 18 10:03:15 EST 2004


On Thu, 18 Nov 2004 06:52:58 -0600, Kent Tenney <ktenney at gmail.com> wrote:
> I'm unsure about naming conventions.
> 
> http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ClassesAttributesMethods
> 
> says::
> 
>  "Methods also should start with a lower case letter.
> The first word of a method should always be a verb
> that describes the action."
> 
> Is this recommending;
> 
>  class Buddy(persistent.Persistent):
>     """Buddy information"""
> 
>     def name(self):
>       return "%s %s" % (self._first, self._last)
> 
> be named;
> 
>   def getName(self):
>       return "%s %s" % (self._first, self._last)

My own opinion here:

Since this is simply getting a simple bit of information from the
object, and since we don't like to expose implementation details (like
the fact that we're computing this string late), something a little
different from this makes more sense.

The "name" attribute should be declared as a zope.schema.TextLine,
making it an attribute rather than a method.  The definition should
then be something like this:

class Buddy(persistent.Persistent):
    """Buddy information"""

    name = property(lambda self: "%s %s" % (self._first, self._last),
                    doc="Full name of this buddy.")


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
Zope Corporation


More information about the Zope3-users mailing list