Re: [Zope3-Users] Re: Newbie Question

2007-02-24 Thread Edward Muller


On Feb 23, 2007, at 5:14 PM, Philipp von Weitershausen wrote:


Edward Muller wrote:

I've done Zope2 stuff in the past, including writing Zope2 Products.
We are working on new hosting software and have decided to use  
Zope 3.
So we're defining our interfaces and have started to define  
classes based on those interfaces and I have a question...
The simple todo app (http://worldcookery.com/files/jeffshell-todo/ 
step1.html) shows the Todo class having three attributes  
(description, details, done). These are all defined in the  
interface using various zope.schema definitions.

But ...
The Boring product (http://products.nidelven-it.no/zope3_boring/)  
does the same thing in the interface with a title attribute. But  
when it gets to the class definition it uses:

def __init__(self, title='Default boring title'):
  self.title = title
The later is more familiar to me coming from Zope 2. Which is  
right? If they are both right, which is *more* right wrt Zope  
3 ... and why?


With respect to interfaces, it's always a good idea to have your  
objects, incl. newly created ones, comply to the interfaces they  
promise to implement. In particular, this means that they should  
have default values for the schema attributes. Frameworks like  
zope.formlib also happen to rely on that.


My book also happens to show class-level attributes a lot. Lately  
I've come to prefer initializing attributes in the constructor  
(__init__) instead, though. It's really a matter of taste, in the  
end. If you like initializing them in the constructor, go with that...


By initializing attributes in the constructor do you mean:

A)

class IA():
 The Letter A 

letter = zope.schema.TextLine(title=The Letter A)

class A():
implements(IA)

def __init__(self,...):
letter = A

or
B)

class A()
implements(IA)

def __init__(self,...):
self.letter = A




--
http://worldcookery.com -- Professional Zope documentation and  
training

Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


--
Edward Muller
Interlix, LLC
Owner

Zope, Plone  Zimbra Hosting

phone: +1.417.862.0573
fax: +1.770.818.5437
--


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Newbie Question

2007-02-24 Thread Philipp von Weitershausen

On 24 Feb 2007, at 16:05 , Edward Muller wrote:

By initializing attributes in the constructor do you mean:

A)

class IA():
 The Letter A 

letter = zope.schema.TextLine(title=The Letter A)

class A():
implements(IA)

def __init__(self,...):
letter = A


This is pretty ineffective, it doesn't store 'letter' on self.



or
B)

class A()
implements(IA)

def __init__(self,...):
self.letter = A


I mean that. Actually, I mean:

class A:
implements(IA)

def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c

perhaps with default values for a,b,c if it makes sense for you.



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Newbie Question

2007-02-23 Thread Edward Muller

Thanks.

The book is on order with amazon. I just want to get as much done as  
possible while I'm at pycon and away from customers ... and  
motivated ... etc.


On Feb 23, 2007, at 4:43 PM, Martin Aspeli wrote:


Edward Muller wrote:

I've done Zope2 stuff in the past, including writing Zope2 Products.
We are working on new hosting software and have decided to use  
Zope 3.
So we're defining our interfaces and have started to define  
classes  based on those interfaces and I have a question...
The simple todo app (http://worldcookery.com/files/jeffshell-todo/  
step1.html) shows the Todo class having three attributes   
(description, details, done). These are all defined in the  
interface  using various zope.schema definitions.

But ...
The Boring product (http://products.nidelven-it.no/zope3_boring/)   
does the same thing in the interface with a title attribute. But  
when  it gets to the class definition it uses:

def __init__(self, title='Default boring title'):
   self.title = title
The later is more familiar to me coming from Zope 2. Which is  
right?  If they are both right, which is *more* right wrt Zope  
3 ... and why?


They are both right, and it doesn't matter.

The interface says when you have an instance of this object, you  
can expect there to be a 'title' attribute. How it got there is  
not that important.


By the way, if you're starting with Zope 3, get Philipp von  
Weitershausen's book Web Component Development with Zope 3  
(www.worldcookery.com). It'll make a lot of this stuff much more  
clear.


Martin

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


--
Edward Muller
Interlix, LLC
Owner

Zope, Plone  Zimbra Hosting

phone: +1.417.862.0573
fax: +1.770.818.5437
--


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Newbie Question

2007-02-23 Thread Philipp von Weitershausen

Edward Muller wrote:

I've done Zope2 stuff in the past, including writing Zope2 Products.

We are working on new hosting software and have decided to use Zope 3.

So we're defining our interfaces and have started to define classes 
based on those interfaces and I have a question...


The simple todo app 
(http://worldcookery.com/files/jeffshell-todo/step1.html) shows the Todo 
class having three attributes (description, details, done). These are 
all defined in the interface using various zope.schema definitions.


But ...

The Boring product (http://products.nidelven-it.no/zope3_boring/) does 
the same thing in the interface with a title attribute. But when it gets 
to the class definition it uses:


def __init__(self, title='Default boring title'):
  self.title = title

The later is more familiar to me coming from Zope 2. Which is right? If 
they are both right, which is *more* right wrt Zope 3 ... and why?


With respect to interfaces, it's always a good idea to have your 
objects, incl. newly created ones, comply to the interfaces they promise 
to implement. In particular, this means that they should have default 
values for the schema attributes. Frameworks like zope.formlib also 
happen to rely on that.


My book also happens to show class-level attributes a lot. Lately I've 
come to prefer initializing attributes in the constructor (__init__) 
instead, though. It's really a matter of taste, in the end. If you like 
initializing them in the constructor, go with that...



--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users