ANNOUNCE: An easier way to write products
It has long bothered me to no end that when I write Python based products that there was a lot of repeat code. Thus violating the DRY pinciple (Don't Repeat Yourself). Also it has been to difficult to get started with a new product, with too many things that had to be just rigth to get going. So you have had to take one of your old products an do extensive searh and replace to get going. Thats a bother. So I have made two simple classes encapsulating my best practices in writing products. They make it REALLY simple to get a product up and running, and has no penalty as such. One class is for making simple products with content. Like articles, user info, Issues, animal info;-) etc. The other class is for making ObjectManagers. They behave like an item, but can contain other objects. So it's folder like. I believe that this kind of functionality should have been built into Zope to begin with, as it would solve the beginner problems for 90% of the people trying to create Python products. Thus flattening the "Z" shaped learning curve. More info here: http://www.zope.org/Members/maxm/HowTo/easyProduct regards Max M
On Thu, Jan 10, 2002 at 12:13:00PM +0100, maxm wrote:
It has long bothered me to no end that when I write Python based products that there was a lot of repeat code. Thus violating the DRY pinciple (Don't Repeat Yourself).
Ever looked to Zope beans? http://www.pault.com/pault/zope/zope_beans.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
From: "Oleg Broytmann" <phd@phd.pp.ru>
Ever looked to Zope beans? http://www.pault.com/pault/zope/zope_beans.html
Yes, but I think my approach is more in line with Zope. To me it is anyway. Also I need a new object format like a hole in the the head ;-) Here I am thinking of the xml format describing the Zope bean. But see below. I don't tink that the "easy" approach is harder than the "bean" approach. They are both about the same amount of lines anyway :-) And how do you set Security on the methods? And if you change the "_properties" in the "easy" approach they are immediately updated in your product. regards Max M ##################################################### ##################################################### <bean> <name> Hello </name> <icon> bean.gif </icon> <version> 0-0-1 </version> <meta> Sample Zope Bean </meta> <property name="greeting" type="string"> Default Greeting </property> <property name="counter" type="string">3</property> <method name="SayGreeting" /> <method name="SaySomething"/> <readme> Hello Zope Bean. This is sample bean to show how Zope Beans work. </readme> </bean> ##################################################### class Hello: "Actual semantics of Hello Bean" def SayGreeting(self): return "Greeting is: " + self.get_greeting() def SaySomething(self, msg, ntimes ): ret = [] for n in range( 1,ntimes ) : ret.append( self.get_greeting() + " By the way ... " + msg) return ret ##################################################### ##################################################### from mxm import mxmSimpleItem class Hello(mxmSimpleItem.mxmSimpleItem): meta_type = 'Hello' _properties = ( {'id':greeting, 'type':'string', 'mode':'w'}, {'id':counter, 'type':'text', 'mode':'w'}, ) __ac_permissions__ = mxmSimpleItem.__ac_permissions__ + ( # label ('View', # methods ('SayGreeting','SaySomething'), # roles ('Anonymous', 'Manager'), ), ) def SayGreeting(self): "" return "Greeting is: " + self.greeting def SaySomething(self, msg, ntimes ): "" ret = [] for n in range( 1,ntimes ) : ret.append( self.greeting + " By the way ... " + msg) return ret def manage_addAction(self, id=None, REQUEST=None): "Add instance to parent ObjectManager" mxmSimpleItem.addClass(self, id, Hello, REQUEST) constructors = (mxmSimpleItem.manage_addForm, manage_addAction) ##################################################### import mxmItem def initialize(context): context.registerClass( mxmItem.mxmItem, constructors = mxmItem.constructors, icon="bean.gif" ) #####################################################
On Thu, Jan 10, 2002 at 01:42:38PM +0100, maxm wrote:
Ever looked to Zope beans? http://www.pault.com/pault/zope/zope_beans.html
Yes, but I think my approach is more in line with Zope. To me it is anyway. Also I need a new object format like a hole in the the head ;-) Here I am thinking of the xml format describing the Zope bean.
But see below. I don't tink that the "easy" approach is harder than the "bean" approach. They are both about the same amount of lines anyway :-)
I didn't mean anything bad, I just pointed out that there is another approach. You approach seems good to me, too. Thank you. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
maxm wrote:
Yes, but I think my approach is more in line with Zope. To me it is anyway. Also I need a new object format like a hole in the the head ;-) Here I am thinking of the xml format describing the Zope bean.
Have you looked at Zope 3? ;-) cheers, Chris
From: "Chris Withers" <chrisw@nipltd.com>
Yes, but I think my approach is more in line with Zope. To me it is anyway. Also I need a new object format like a hole in the the head ;-) Here I am thinking of the xml format describing the Zope bean.
Have you looked at Zope 3? ;-)
Yes :-( I came to Zope because I LOVE Python, and it fits my brain. And then I get smothered in xml. bugger :-) regards Max M
This is an official warning. The word 'bugger' is copyright Phil Harris (2001). Please refrain from gratuitous use of 'bugger' as legal proceedings will be taken. Thank you for your time. :) ----- Original Message ----- From: "maxm" <maxm@mxm.dk> <snip>lots of interesting stuff<snip>
bugger :-)
regards Max M
I too think that zope needed this class at the beginning. It has been way too hard to create products through python and zope for too long. Can I make a few suggestions: I am an old hacker ( maybe even unemployable ), but I remember in C we used to wrap data structures around macros. Now in python, there aren't really any macros unless you consider the lamba function a type of one, but maybe you can add to your class simple methods like the following: set_meta_type( typename ) set_constructors( ... ) set_properties( name, type, mode ) set_roles( list_roles ) set_users( list_users ) Then a new class definition might look a lot clean and less error prone, i.e.: for mxm import mxmSimpleItem class easyArticle( mxmSimpleItem.mxmSimpleItem ): set_meta_type( 'EasyArticle') set_property( 'title','string','w' ) # or better yet ..... set_property( 'summary', mxm.TYPE_TEXT, mxm.PROPERTY_PERMISSION_WRITE ) set_property( 'content', mxm.TYPE_TEXT, mxm.PROPERTY_PERMISSION_WRITE ) set_property( 'author', mxm.TYPE_STRING, mxm.PROPERTY_PERMISSION_WRITE ) # and if you want to be really cool .. you can have default values for properties # like TYPE_STRING and PERMISSION_WRITE to make things easier for use old folks ;-). One more thing, maybe this is obvious -- but a simple example of inheritence from something like catalog aware base class where of course, the base catalog class is first. Thanks for the maxm class, nice job, Luis. ----- Original Message ----- From: "maxm" <maxm@mxm.dk> To: <zope@zope.org> Sent: Thursday, January 10, 2002 4:13 AM Subject: [Zope] ANNOUNCE: An easier way to write products
It has long bothered me to no end that when I write Python based products that there was a lot of repeat code. Thus violating the DRY pinciple (Don't Repeat Yourself).
Also it has been to difficult to get started with a new product, with too many things that had to be just rigth to get going. So you have had to take one of your old products an do extensive searh and replace to get going. Thats a bother.
So I have made two simple classes encapsulating my best practices in writing products. They make it REALLY simple to get a product up and running, and has no penalty as such.
One class is for making simple products with content. Like articles, user info, Issues, animal info;-) etc.
The other class is for making ObjectManagers. They behave like an item, but can contain other objects. So it's folder like.
I believe that this kind of functionality should have been built into Zope to begin with, as it would solve the beginner problems for 90% of the people trying to create Python products.
Thus flattening the "Z" shaped learning curve.
More info here:
http://www.zope.org/Members/maxm/HowTo/easyProduct
regards Max M
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Luis Cortes wrote:
I too think that zope needed this class at the beginning. It has been way too hard to create products through python and zope for too long.
Can I make a few suggestions:
lots of suggestions snipped ... I do understand you suggestions, and your reason for them. But I believe them to be another speedbump on the learning curve. Because as you develop your products, and add stuff to them, they become more and more like regular products. And then you will have to unlearn it again.
One more thing, maybe this is obvious -- but a simple example of inheritence from something like catalog aware base class where of course, the base catalog class is first.
Hmm ... yes. That might be a good idea. I will probably do that.
Thanks for the maxm class, nice job,
Thank you! It's nice that they are getting used/liked. regards Max M
Max M wrote:
One more thing, maybe this is obvious -- but a simple example of inheritence from something like catalog aware base class where of course, the base catalog class is first.
Hmm ... yes. That might be a good idea. I will probably do that.
Another thing I'd like to try (that I didn't try already), is to try to inherit from file and see what happens. I'm still a newbie product-joe-maker. If I have some interesting newbie docs/experiements, I'll send them.
Thank you! It's nice that they are getting used/liked.
regards Max M
I'd like to thank you as well, as this class will really ease my learning curve (and most probably for others as well). Philippe
participants (7)
-
Chris Withers -
Luis Cortes -
Max M -
maxm -
Oleg Broytmann -
Phil Harris -
Philippe Jadin