Pythonic way of web-programming

Alex Martelli aleax at aleax.it
Wed Apr 16 04:18:17 EDT 2003


Ian Bicking wrote:

> On Tue, 2003-04-15 at 03:11, Alex Martelli wrote:
>> However -- look at the XML situation for contrast.  There IS just such
>> a standard (and parts of it ARE in the standard libraries, while others,
>> PyXML stuff, integrate as seamlessly as they can with those via some
>> import tricks).  AND YET -- you guys have developed and maintain PyRXP,
>> which uses substantially different interfaces -- *AND WELL IT DOES*,
>> because thanks to the different interfaces (trees of bare tuples, or
>> lists as the case may be, rather than intricate objects as in DOM) it
>> can save a LOT of memory, and generally zip along much, much faster.
>> 
>> Aren't there analogies here...?
> 
> There may be compelling differences in some areas.  For instance, a
> template that is DOM-like (i.e., externally controlled) vs. a template
> that is self-evaluating, like Cheetah.  But among self-evaluating
> templates, the interface seems like it should be possible to unify.

Possible, yes.  Feasible, I dunno.  Compare Cheetah and preppy, which
both process templates to produce Python modules.  preppy does it in
a very simple, rather Pythonic way -- inserting "directives" enclosed
in {{...}} that are Python expressions or a few Python statements
modified to have explicit endif/endfor/&c termination rather than
relying on indentation.  Any Python programmer should have no problem
understanding preppy in 10 minutes and then happily using e.g.
    {{myobject.func()}}
or
    {{myobject['index']}}
or
    {{myobject.attr}}
&c &c in a fully appropriate manner -- since by definition a Python
programmer already understands perfectly the difference between
calling a function (and KNOWS you need empty parentheses when you
call a function without arguments -- something that keeps tripping
beginners up, btw), indexing a container, accessing an attribute.

But suppose your design intention is different -- you want your
templates to be maintained by NON-programmers, people which DO
have problems understanding the differences between the above
distinct concepts!  In Cheetah, the above constructs would be
    $myobject.func
    $myobject.index
    $myobject.attr
i.e., totally polymorphic.  The Cheetah designer, on the basis of
a LOT of experience trying to have non-programmers maintain
templates, believe this extreme polymorphism makes things VERY
much easier for non-programmers (perhaps particularly ones that
have some previous exposure to languageoids such as Javascript
and VBScript that may also try to hide such differences...).

So who's right?  Quite possibly both -=- a programmer will find it
easier and more productive to use and maintain preppy templates,
closer to Python, and a non-programmer Cheetah templates, which
requires him or her to learn fewer concepts (and do NOT require
empty parentheses for argumentless function calls, in particular).


> There are deep differences and shallow ones.  It would be really nice to
> get rid of the shallow ones.

Personally I agree that the difference between {{x.y()}} and $x.y is
quite shallow.  But I don't know if it's best gotten rid of -- I _have_
seen nonprogrammers (and even programmers with e.g. a Pascal background)
wrestle with forgetting the () over and over, yet as a programmer I FAR
prefer the clarity of the distinctions drawn by preppy (and Python)
for programming use...


Alex





More information about the Python-list mailing list