[Python-ideas] Statements vs Expressions... why?
cliff at develix.com
Thu Sep 11 20:08:35 CEST 2008
On Thu, 2008-09-11 at 11:01 -0400, Mike Meyer wrote:
> On Wed, 10 Sep 2008 14:54:44 -0700
> Cliff Wells <cliff at develix.com> wrote:
> > There were several design decisions to be made when designing Breve, the
> > first and foremost being "will Breve templates be full-blown Python
> > programs or will they be limited to expressions?". I chose the latter
> > for a few reasons:
> That seems to be a very poor decision. If you want Breve templates to
> play well with Python code (i.e. - be able to have Breve classes
> inherit from Python classes and vice versa - but I guess without
> statements, you don't have classes, so all of that is moot. Of course,
> not having classes seems like a bad idea as well.
Just to be clear because it appears to me you aren't quite following:
Breve templates *are* Python code, or more exactly, they are a single
Python expression. There is no preprocessor or interpreter that turns
Breve into Python. It's just a bunch of class-magic.
The decision to be a single large expression is largely because this is
a *template* engine and an expression maps most directly to XML because
XML is structured similarly:
title [ 'A Brevé Template' ]
h1 [ 'Briefly, Brevé' ], br,
div ( style = 'text-align: center;' ) [
span [ '''
As you can see, Brevé maps very
directly to the final HTML output.
This is opposed to allowing the full of Python which would require a lot
of syntax that is extraneous to the markup being generated (and most
importantly would have caused a visual disjoint between the Breve source
template and the final output).
> Further, why do you feel that Breve templates - even if limited to
> expressions - need to be limited to what Python expressions can do?
Again, because Breve *is* Python. It's an internal DSL. Please see
for a definition of what that means. Another example of an internal DSL
that's more widely used would be SQLAlchemy.
More information about the Python-ideas