RE: generator expressions: performance anomaly?

Discussion in 'Python' started by Robert Brewer, Jan 18, 2005.

  1. Jeremy Bowers wrote:
    > On Tue, 18 Jan 2005 14:05:15 +0000, Antoon Pardon wrote:
    > > I don't see how generating byte code for a = 9; when seeing the
    > > expression a = 3 + 6, would be a problem for non-functional
    > > languages.

    >
    > Ultimately, the use is fairly limited; I can't imagine the
    > execution time saved would reach the time of implementation
    > for weeks after a release, even aggregating across all Python
    > use in the world, and "real time gained" (i.e., time useful
    > to a human) would probably never add up to the
    > implementation time. So why bother? That's a horrid trade off
    > when there are so many other real gains to be had.


    Especially since you can already do it explicitly with Raymond
    Hettinger's cookbook recipe:
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940


    Robert Brewer
    MIS
    Amor Ministries
    Robert Brewer, Jan 18, 2005
    #1
    1. Advertising

  2. macros (was: RE: generator expressions: performance anomaly?)

    On Tue, 18 Jan 2005 12:59:07 -0800, Robert Brewer wrote:
    > Especially since you can already do it explicitly with Raymond
    > Hettinger's cookbook recipe:
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940


    You know, Guido might as well give in now on the Macro issue. If he
    doesn't come up with something himself, apparently we'll just hack
    bytecode. I'm not sure that's a gain. (To be fair, I can see some
    arguments that it is, so that "I'm not sure" isn't a
    passive-aggressive/sarcastic snipe like most people use it in this
    context; I mean it literally.)

    (I expect if we ever do see them, this will be the basic argument used. I
    guess you could call it Historic Inevitably. :) )

    I'm not just basing it on this one thing, I'm basing this on all the
    bytecode hacks I've seen.
    Jeremy Bowers, Jan 18, 2005
    #2
    1. Advertising

  3. Robert Brewer

    Jeff Shannon Guest

    Re: macros

    Jeremy Bowers wrote:

    > On Tue, 18 Jan 2005 12:59:07 -0800, Robert Brewer wrote:
    >
    > You know, Guido might as well give in now on the Macro issue. If he
    > doesn't come up with something himself, apparently we'll just hack
    > bytecode. I'm not sure that's a gain.


    I think that this sort of thing is better to have as an explicitly
    risky hack, than as an endorsed part of the language. The mere fact
    that this *is* something that one can clearly tell is working around
    certain deliberate limitations is a big warning sign, and it makes it
    much less likely to be used extensively. Relatively few people are
    going to want to use something called "bytecodehacks" in a
    mission-critical piece of software, compared to the number who'd be
    perfectly happy to use a language's built-in macro facilities, so at
    least it keeps the actual usage down to a somewhat more manageable level.

    To rephrase this a bit more succinctly ;) there's a big difference
    between having no practical way to prevent something, and actually
    encouraging it.

    Jeff Shannon
    Technician/Programmer
    Credit International
    Jeff Shannon, Jan 18, 2005
    #3
  4. Robert Brewer

    Evan Simpson Guest

    Re: macros

    Jeremy Bowers wrote:
    > You know, Guido might as well give in now on the Macro issue. If he
    > doesn't come up with something himself, apparently we'll just hack
    > bytecode.


    Ah, hacking bytecode isn't where it's at anymore. These days, you use
    the compiler package and munge the AST. Hygenic!

    That said, the big brake on macros implemented either of these ways is
    the fact that the source still has to be syntactically valid python.
    You can make a macro FOOBAR that works in these ways:

    x = FOOBAR(some, arguments) # Pseudo-function

    if FOOBAR:
    a.suite # Pseudo-'if' statement

    { FOOBAR: expr } # Pseudo-throwaway dict

    ....but not these:

    FOOBAR:
    a.suite # Suite that explicity depends on FOOBAR for meaning

    x = a FOOBAR b # expression with pseudo-keyword

    What we need is a generic suite statement, something like:

    gensuite ::= [decorators] "do:" suite

    ....where the suite is treated like the body of an anonymous function
    that is called and discarded immediately after it is defined. In other
    words, the code

    @f2
    do: pass

    ....is roughly equivalent to:

    @f2
    def <unique name>(): pass
    <unique name>()
    del <unique name>

    Then we could abuse the heck out of it by perverting the AST of

    @FOOBAR
    do:
    stuff

    That's never going to happen, tho.

    Cheers,

    Evan @ 4-am
    Evan Simpson, Jan 18, 2005
    #4
  5. Re: macros

    On Tue, 18 Jan 2005 14:36:08 -0800, Jeff Shannon wrote:
    > I think that this sort of thing is better to have as an explicitly
    > risky hack, than as an endorsed part of the language. The mere fact
    > that this *is* something that one can clearly tell is working around
    > certain deliberate limitations is a big warning sign, and it makes it
    > much less likely to be used extensively. Relatively few people are
    > going to want to use something called "bytecodehacks" in a
    > mission-critical piece of software, compared to the number who'd be
    > perfectly happy to use a language's built-in macro facilities, so at
    > least it keeps the actual usage down to a somewhat more manageable level.
    >
    > To rephrase this a bit more succinctly ;) there's a big difference
    > between having no practical way to prevent something, and actually
    > encouraging it.


    Hey, argument, there you are. I figured you'd work your way out somehow
    without me having to type you.

    :)

    The counterargument that leaps to mind is that if enough people do it,
    there's a need, and that need should be met explicitly rather than with
    "hacks", for the benefit of all.

    Again, I emphasize my ambivalence. Are there "enough"? (It's hard to tell,
    maybe if it weren't so hard more would do it.) Is the benefit big enough?
    Is "the need" the need to tell people "stop juggling chainsaws!"? (In
    which case I guess "the need" has been met.)

    Basically, I'm willing to trust Guido overall on the grounds that he has
    earned it. But I still can't help but wonder if outright dismissal isn't
    missing something that could be useful and positive if Guido et al turned
    their minds to it. But then, I have no idea what it may be and it may be
    impossible.

    Like I said, I'm torn on this one :)
    Jeremy Bowers, Jan 18, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas
    Replies:
    0
    Views:
    594
    Jay Douglas
    Aug 15, 2003
  2. John Machin
    Replies:
    10
    Views:
    531
    Raymond Hettinger
    Jan 16, 2005
  3. Delaney, Timothy C (Timothy)

    RE: generator expressions: performance anomaly?

    Delaney, Timothy C (Timothy), Jan 16, 2005, in forum: Python
    Replies:
    36
    Views:
    745
    Raymond Hettinger
    Jan 19, 2005
  4. Steven Bethard
    Replies:
    9
    Views:
    266
    Steven Bethard
    Jan 25, 2005
  5. Noman Shapiro
    Replies:
    0
    Views:
    222
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page