quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Fraser <dav...@sjsoft.com>
Subject OO Python alternative to PSP
Date Thu, 10 Apr 2003 19:10:05 GMT
Michael C. Neel wrote:

>	I'm not a fan of PHP, I don't think it lends itself well to
>large systems.  This is because I don't care to have heavy amounts of
>code mixed into a template; I don't like having my data, design, and
>logic mixing (and yes Sterling, I read your thoughts on that in your
>blog =p).  Not to say that is not possible in PHP, it is, but to me it
>feels a bit awkward and may lead to the several include issue I
>mentioned above.
>	So my point is in here that for psp, we should be open to other
>methods than the ones used in php and not assume that the php methods
>are the best ones for python.  Which brings me to my next point...
>3.  What is psp offering over php?  Are we simply going for a php but
>with python syntax?  I'm not sure that would be the best use of the
>strengths of the python language.  I am a strong fan of the Albatross
>system, which I think does make use of the python strengths such as
>extensibility and, for lack of a better term, "clean" code.
In fact, when I first saw Sterling's blog, it made me think "what other 
ways are there to do this that would be more Python-esque"?
I don't think any of the existing templating systems really seem to do 
that , not even Albatross
I think it's good that there are a variety available.
Note: the following is not intended of criticism of psp, but as a 
discussion of a different system
Maybe we need another new one in addition to psp (not as competition, 
but as an alternative)

My observations:

Sometimes people want to write a lot of HTML, with some scripting in 
between. (psp is good for this. To me, Albatross seems like this too)
Sometimes people want to write more scripting, with some HTML in between.
In addition, it would be quite cool to build something that can produce 
other kinds of text output as well as HTML (or at least variants of it).
What I really want is to feel like I'm programming Python, but to be 
able to produce HTML in an easy way... I don't want to have things that 
are essentially functions but which have to be written as html tags, 
like Albatross:
Which means, for example, that for me the indentation is critical. 
That's one of Python's strengths.
(and HTML code doesn't care about indentation, so I don't see it as a 

"Templating" has some advantages, but what I generally do with 
mod_python is create classes for the presentation (HTML) which are 
separate to the logic of the application, and use those ... this is a 
more programming centric approach which may not be useful for all 
situations, but does also give the ability to make very complex systems 
without interweaving code.

For example, in my company, we produce lots of things in tables with 
different cells being different colours etc. We have a system where 
there is a base "Widget" (but could be called something else) class, 
which has a function .gethtml(). We have lots of other Widgets derived 
from this (Link, TableLayout, TableCell, Button, Form, etc).

The thing is, the set of objects that is required and the way they work 
is probably different for each application. Which is why something like 
Zope ends up being too heavy - you don't want to take the whole 
infrastucture out of the hands of the programmer...

One of the main concepts I think is important is the notion that User 
Interface (which is what a web page is) is best coded in a declarative 
HTML is good at this. Even VB is good at this (yes I generally hate it, 
but look below)! But using standard Python functions or objects doesn't 
really seem to work.
For example, in VB, a Form is saved in a text format something like this 
(though nobody is meant to edit these, I think the format is cool and 
Form AddUser
    TextField Username
    TextField Password
    Button Add
End Form
(and there can be multiple levels in it).

So what I've always wanted to do in Python is say something like this:

class Form(Widget):

class AddUserForm:
  # list the members of the form. here the order matters i.e. 
corresponds to the order of display
  TextField username
  TextField password(hidden=true)
  Button Add:
     def submit(self):
       users.adduser(self.username, self.password)

Page ShowFormPage:
  AddUserForm adduserform(mode=Form.display)

Page SubmitFormPage:
  AddUserForm adduserform(mode=Form.process)

Then to call it, you could have a handler, that says something like this:

def handler(req):
  if req.url == showformurl:
  elif req.url == submitformurl:

The trouble is this isn't standard Python code. It kind of breaks down 
the class/object distinction although I think that could be handled.

OK, there's lots of different ideas in there, I just wonder what parts 
of this approach other people like/hate :-)

The main idea is the change in syntax enabling you to declare 
variables/class members in a non-Pythonish (at the moment) way:
ClassName object(*args)
with optional extension of the class:
ClassName object(*args):
  # my own extra members go here...
Basically you could translate
  ClassName object(*args)
  object = ClassName(args)
  ClassName object (*args):
  class _ClassName_object(ClassName):
  object = _ClassName_object(args)
The difficulty but possible strength would come in working out what to 
do with args without people having to write lots of wrapping code.

So when I saw Sterling's psp, having thought of this kind of approach 
before, it made me wonder, maybe I should actually do it...
Syntax like this could be restricted to a .pwp (Python web page) or 
something like that, the rest of the code could be ordinary Python 
(logic etc).

Another important thing would be making it easy for people to built Widgets.
A possible way to do this would be as follows:

Widget Button(buttontype, value, label):
  "<button type=%(buttontype)s value=%(value)s>"

This requires a different kind of parsing to the object-building stuff 
above, since the objects have no names...

Translate to:
  class Button(Widget):
    def __init__(self, buttontype, value, label):
      self.members = [
        "<button type=%(buttontype)s value=%(value)s>",

Then we just need to do simple handling of the members.

Hmmmm ... Late and travelling tomorrow, but I just thought I'd write 
this and see what people think.
Probably needs clarification. But comments appreciated


View raw message