473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PEP318: radical notion

Apologies for feeding the fire, when we are rallying around a consensus,
but I've been concerned about the clash between syntax and semantics, and
I've finally reached a mini-epiphany:

The problem with PEP318 is that it is too powerful, and tries to do too
much. It is a sledgehammer for attacking three problems:

1) Metadata, a la Java and C#
2) class & static method defs
3) Arbitrary post-definitional transformations of functions.

(where 2 is a special frequent use case that's part of 3).

We have ueber-powerful semantics (implementing 3), trying to solve
problems with very different semantics (e.g., 1).

OK, that's what I know. Here's a proprosal, that may or may not work,
because my knowledge of metaclass programming is only sketchy:

1) Make PEP318 *only* implement problem (1). That is, create sematics for
defining and retrieving function/method/class metadata
2) Create a new default metaclass that uses metadata for class/static
method definitions to perform the necessary class/staticmethod
transformations. Perhaps use this metaclass as default in 2.4 only via a
"from __future__ import foo".
3) Leave any arbitrary transformations to be implemented via custom
metaclasses -- these metaclasses will have access to the custom metadata
to trigger method def transformations.

Arien
Jul 18 '05 #1
14 1643
Arien Malec wrote:
Apologies for feeding the fire, when we are rallying around a consensus,
but I've been concerned about the clash between syntax and semantics, and
I've finally reached a mini-epiphany:

The problem with PEP318 is that it is too powerful, and tries to do too
much. It is a sledgehammer for attacking three problems:

[snip]

I believe your mini-epiphany has been reached by several other people
in this forum and discussed at length, certainly not in exactly the
same words but surely in a very similar form.

If you've checked the archives and seen those discussions, but still
feel you have something really original to contribute, I suggest
contrasting your argument with those previous ones to demonstrate
how it is different and worth further discussion at this point.
If you don't, I expect many people will feel you are just rehashing
something very late in the game and will mostly ignore your post.

-Peter
Jul 18 '05 #2
Arien Malec wrote:
Apologies for feeding the fire, when we are rallying around a consensus,
but I've been concerned about the clash between syntax and semantics, and
I've finally reached a mini-epiphany:

The problem with PEP318 is that it is too powerful, and tries to do too
much. It is a sledgehammer for attacking three problems:

1) Metadata, a la Java and C#
2) class & static method defs
3) Arbitrary post-definitional transformations of functions.

(where 2 is a special frequent use case that's part of 3).

We have ueber-powerful semantics (implementing 3), trying to solve
problems with very different semantics (e.g., 1).

OK, that's what I know. Here's a proprosal, that may or may not work,
because my knowledge of metaclass programming is only sketchy:

1) Make PEP318 *only* implement problem (1). That is, create sematics for
defining and retrieving function/method/class metadata
2) Create a new default metaclass that uses metadata for class/static
method definitions to perform the necessary class/staticmethod
transformations. Perhaps use this metaclass as default in 2.4 only via a
"from __future__ import foo".
3) Leave any arbitrary transformations to be implemented via custom
metaclasses -- these metaclasses will have access to the custom metadata
to trigger method def transformations.

Arien


Unfortunately for you, you can use decorators on normal functions and not
only on member functions. It rules out any metaclass based implementation.
Jul 18 '05 #3
Peter Hansen <pe***@engcorp.com> wrote in
news:Cs********************@powergate.ca:
Arien Malec wrote:
Apologies for feeding the fire, when we are rallying around a
consensus, but I've been concerned about the clash between syntax and
semantics, and I've finally reached a mini-epiphany:

The problem with PEP318 is that it is too powerful, and tries to do
too much. It is a sledgehammer for attacking three problems:

[snip]

I believe your mini-epiphany has been reached by several other people
in this forum and discussed at length, certainly not in exactly the
same words but surely in a very similar form.


I haven't heard too much resolution about it. The discussion I've seen
has been oriented mostly around syntax, partly around "this is ugly but
Guido says it goes".

I haven't heard the "it's really not ugly, and here's why" part of this.

Arien

Arien
Jul 18 '05 #4
JCM
Arien Malec <ar*********@yahoo.com.remove> wrote:
Apologies for feeding the fire, when we are rallying around a consensus,
but I've been concerned about the clash between syntax and semantics, and
I've finally reached a mini-epiphany: The problem with PEP318 is that it is too powerful, and tries to do too
much. It is a sledgehammer for attacking three problems: 1) Metadata, a la Java and C#
2) class & static method defs
3) Arbitrary post-definitional transformations of functions.


Agreed. I think trying to address all of this with decorators is the
wrong way to go.
Jul 18 '05 #5
On Mon, 23 Aug 2004 18:12:57 GMT, Arien Malec
<ar*********@yahoo.com.REMOVE> wrote:

The problem with PEP318 is that it is too powerful, and tries to do too
much. It is a sledgehammer for attacking three problems:

1) Metadata, a la Java and C#
2) class & static method defs
3) Arbitrary post-definitional transformations of functions.
The problem as you see it was, I think, was very well put forth by
Chris King early in the game, and then promptly bypassed.

Guido, as late as May or June, I think, suggested that no new syntax
be added to 2.4. But then backed off that position, to the point that
discussion about anything other than *which* new syntax to empower the
sledgehammer, has become anti-social, or something.

Perhaps Guido could not answer the question to himself, or anybody
else, as to - no new syntax in 2.4, pending what.

Folks a lot more qualified than myself have expressed an opinion that
the reprecussions here are not likely to be pretty. And been booed off
the stage, and considerately left the stage - it not being their
problem in the end, in anycase.

So it is my opinion the weight of discussion on python-list at this
point does not accurately reflect the weight of sentiment on the
issue. Most folks don't like being anti-social.

I allow myself to be. Sometimes.

Art

Arien


Jul 18 '05 #6
Christophe Cavalaria <ch*************@free.fr> wrote in message news:<41*********************@news.free.fr>...
Arien Malec wrote:
1) Make PEP318 *only* implement problem (1). That is, create sematics for
defining and retrieving function/method/class metadata
2) Create a new default metaclass that uses metadata for class/static
method definitions to perform the necessary class/staticmethod
transformations. Perhaps use this metaclass as default in 2.4 only via a
"from __future__ import foo".
3) Leave any arbitrary transformations to be implemented via custom
metaclasses -- these metaclasses will have access to the custom metadata
to trigger method def transformations.

Unfortunately for you, you can use decorators on normal functions and not
only on member functions. It rules out any metaclass based implementation.


Is there a valid use case that supports arbitrary magical non-metadata
transformations of standalone functions?

Arien
Jul 18 '05 #7
Arien Malec wrote:
Christophe Cavalaria <ch*************@free.fr> wrote in message
news:<41*********************@news.free.fr>...
Arien Malec wrote:

> 1) Make PEP318 *only* implement problem (1). That is, create sematics
> for defining and retrieving function/method/class metadata
> 2) Create a new default metaclass that uses metadata for class/static
> method definitions to perform the necessary class/staticmethod
> transformations. Perhaps use this metaclass as default in 2.4 only via
> a "from __future__ import foo".
> 3) Leave any arbitrary transformations to be implemented via custom
> metaclasses -- these metaclasses will have access to the custom
> metadata to trigger method def transformations.

Unfortunately for you, you can use decorators on normal functions and not
only on member functions. It rules out any metaclass based
implementation.


Is there a valid use case that supports arbitrary magical non-metadata
transformations of standalone functions?

Arien


memoize for example. No metadata, only transformation, doesn't really apply
to a member function in fact ( although it might be possible à

Why is it that there are always some people who doesn't understand all the
possibilities of decorators and so want to minimise their usefulness ?
Jul 18 '05 #8
On Wed, 25 Aug 2004 00:57:41 +0200, Christophe Cavalaria
<ch*************@free.fr> wrote:
Why is it that there are always some people who doesn't understand all the
possibilities of decorators and so want to minimise their usefulness ?


I can't understand, yet, talking about decorators as if they *are*
something.

We have shortedened some syntax.

Before alpha 2, decorators were not.

Now they ain't.

;)

Art
Jul 18 '05 #9
Christophe Cavalaria <ch*************@free.fr> wrote in
news:41**********************@news.free.fr:
Arien Malec wrote:
Is there a valid use case that supports arbitrary magical
non-metadata transformations of standalone functions?


memoize for example. No metadata, only transformation, doesn't really
apply to a member function in fact ( although it might be possible à


Classically, memoize is implemented as function composition, or as a true
GoF decorator. It's not clear (to me, at least) how much benefit the
syntactic sugar gets you.
Why is it that there are always some people who doesn't understand all
the possibilities of decorators and so want to minimise their
usefulness ?


I dunno. Who are those people? My objection to PEP318 is that makes
something that's really powerful (arbitrary transformation) look like a
trivial declaration. In Common Lisp, for instance, a defmacro form hints
that powerful mojo is being performed; the same is not apparent in
PEP318.

Arien

Jul 18 '05 #10
Arien Malec wrote:
....
Is there a valid use case that supports arbitrary magical non-metadata
transformations of standalone functions?


2 use cases (in addition to others people have mentioned) I can think of
off the top of my head:
* Adding call tracing to specific functions without disturbing the
code.
* Wrapping generator functions so that they can recieve data in an
IPC manner.

using:
trace(level=1)
def somefunc(foo):
if bla(foo) == 1:
return weeble(foo)
elif baz(foo) == 2:
return wobble(foo)
elif bibble(foo) == 3:
return jeeble(foo)
elif bloing(foo) == 4:
return jobble(foo)
elif nickynickynack(foo) == 5:
return fnarkle(foo)

Adding a trace function in here temporarily would mean you can intercept
both the call and the return values conveniently - as you would with
memoise (say), but you can do something interesting with it.
Furthermore, if you're not sure your memoise decorator is doing the
right thing you could do something like:

using:
trace(level=1)
memoise
def somefunc(foo):
if bla(foo) == 1: ...

Followed by...

using:
memoise
trace(level=1)
def somefunc(foo):
if bla(foo) == 1: ...

And potentially:

using:
trace(level=1)
def somefunc(foo):
if bla(foo) == 1: ...

And do a compare and contrast of results. Behaviour is transformed,
there is no metadata involved and it's suitable for any function -
whether it's part of a class's namespace (as any kind of method), or
not. Since they're not necessarily part of a class you can't use
metaclasses to do this.

Regards,
Michael.
--
Mi************@rd.bbc.co.uk
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.
Jul 18 '05 #11
Michael Sparks <mi******@rd.bbc.co.uk> wrote in
news:cg**********@nntp0.reith.bbc.co.uk:
Arien Malec wrote:
...
Is there a valid use case that supports arbitrary magical
non-metadata transformations of standalone functions?


2 use cases (in addition to others people have mentioned) I can think
of off the top of my head:
* Adding call tracing to specific functions without disturbing the
code.
* Wrapping generator functions so that they can recieve data in an
IPC manner.


PEP318 = AOP by another name?

I can think of a couple of workaround for the issue you raise:

1) Allow a "module metaclass" -- something that can intercept function
defs at a module level, read metadata, and apply necessary
transformations

2) Have a default class that standalone functions are static members of,
which can have a default metaclass associated with it.

I personally think that separating metadata from transformations is a
much cleaner approach than using the transformation implementation for
everything.

Arien
Jul 18 '05 #12

On 25-aug-04, at 0:13, Arien Malec wrote:

Is there a valid use case that supports arbitrary magical non-metadata
transformations of standalone functions?


Barray Warsaw has mentioned several times on py-dev that he has
actually used several of the propesed syntaxes to rewrite existing code
that uses decorators (IIRC mailman).

Ronald

Jul 18 '05 #13
Arien Malec wrote:
Christophe Cavalaria <ch*************@free.fr> wrote in
news:41**********************@news.free.fr:
Arien Malec wrote:
Is there a valid use case that supports arbitrary magical
non-metadata transformations of standalone functions?


memoize for example. No metadata, only transformation, doesn't really
apply to a member function in fact ( although it might be possible à


Classically, memoize is implemented as function composition, or as a true
GoF decorator. It's not clear (to me, at least) how much benefit the
syntactic sugar gets you.


Ease of writing and reading aren't benefits for you ?
Why is it that there are always some people who doesn't understand all
the possibilities of decorators and so want to minimise their
usefulness ?


I dunno. Who are those people? My objection to PEP318 is that makes
something that's really powerful (arbitrary transformation) look like a
trivial declaration.


If that's your objection, say it. I'm ok with that. But don't do that :

people : we need generators for usage a, b, c
you : here is a great syntax. It handles case a and b in such a beautiful
way and it's much much better that some other proposal
people : what about case c ?
you : case what ?
In Common Lisp, for instance, a defmacro form hints
that powerful mojo is being performed; the same is not apparent in
PEP318.


Well, if the @pie form isn't a clear way to say that something strange is
going on, I don't know what is :)

Jul 18 '05 #14
Christophe Cavalaria <ch*************@free.fr> wrote in message news:<41***********************@news.free.fr>...
Arien Malec wrote:
Christophe Cavalaria <ch*************@free.fr> wrote in
news:41**********************@news.free.fr:
Why is it that there are always some people who doesn't understand all
the possibilities of decorators and so want to minimise their
usefulness ?


I dunno. Who are those people? My objection to PEP318 is that makes
something that's really powerful (arbitrary transformation) look like a
trivial declaration.


If that's your objection, say it. I'm ok with that.


I did, see the top of this thread.

To be clear, I don't deny that autotransformers of module-scoped
functions wouldn't be quite useful; I'm queasy about using the same
syntax to add metadata AND mangle functions and methods.

My thought was that metadata + metaclasses gives the same ability as
PEP318 in a clean way to a suffiently large subset of use cases that
it's better to go with that and figure out separately how to perform
metaclass-like magic to module-scoped functions than it is to apply
the function autotransformation semantics to solve all problems.

Arien
Jul 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stephen Horne | last post by:
It just occurred to me that if decorators really catch on, there could be cases where they are applied repeatedly to many functions, and possibly with many decorators. Combine that with many (and...
10
by: Sean Ross | last post by:
Here's a breakdown of most of the syntax discussed re: PEP318 using an example from python-dev. There are probably several more (I've added ). The example applies both function decoration and...
30
by: ajsiegel | last post by:
Arthur wrote: >> And either intuitively, or consciously, he is doing something that >> offsets it from something truly intergrated into the core of the >> language. By breakling all of his own...
5
by: mojo | last post by:
Is there a nice way to have HTML display mathematical expressions that contain radical symbols (square root, cube root, ..., nth root) that look nice. The best I can come up with is by having a...
0
by: JoanneC | last post by:
Hi, Just a quick question, why is radical sorting not supported in .NET framework for Traditional Chinese, since this is a popular sorting method. Thanks
1
by: dhall5 | last post by:
Hi everyone, My company advertises "not off the shelf" programming and what we provide can be fit to each clients needs. With that the biggest goal I have is to have the 80% of what everyone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.