durusmail: qp: Another Proposed Template Notation
Another Proposed Template Notation
2007-11-01
Re: Another Proposed Template Notation
2007-11-01
2007-11-01
2007-11-01
2007-11-01
Re: Another Proposed Template Notation
2007-11-02
2007-11-02
2007-11-02
2007-11-02
2007-11-02
Another Proposed Template Notation
mario ruggier
2007-11-01
On Nov 1, 2007, at 4:28 PM, David Binger wrote:

> Currently, templates are denoted by [html] (or [plain]) between the
> function name
> and the parameter list.
>
> I've proposed (and implemented) an alternative form I call template
> decorators,
> where "@[xml]" or "@[str]" appears on the line before the def.
>
> I've thought of another possibility that I want to run by you.
>
> In python 3, we can (optionally) annotate parameters and functions
> like this:
>
> def f(x:int, y:list) -> float:
>
> I'm proposing using a similar annotation syntax for annotating the
> function name,
> using a colon and either "xml" or "str" to say that the function is a
> template
> and that it should be compiled using the "xml" transformation, or the
> "str"
> transformation.
>
> def f:xml():
>
> or
>
> def f:str():

I think improved grep-friendliness is important, and for that alone I'd
prefer this syntax. I have one reservation though. The py3 proposed
function annotations imply a type -- of a parameter or of the
function's return value. The usage here does not -- it "modulates",
indicates some sort of special behaviour. Maybe a modulator should
precede... would this be too strange:

def xml:f ():
def str:f ():

Note the extra space... that i still prefer the look of for function
defs ;-)

Also, in general my functions end up having a name longer than a single
character, so maybe one should stare also at longer names, such as:

def xml:render_something ():
def str:render_something ():

I certainly prefer this to the template decorator syntax, but i am
anyhow less sure of how this improves on:

def render_something [xml] ():
def render_something [str] ():

> Maybe this notation fits best into the python of the future.
>
> I like that it is as grep-able as the current notation, but a little
> shorter.

Current...  meaning [xml] and [str] syntax?

> What do you think?

The compiler doesn't, but... I like it ;-)

reply