__autoinit__

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Tue Jul 12 02:54:06 EDT 2005


--- Mike Meyer <mwm at mired.org> wrote:
> Remember that what we're suggesting is just syntactic sugar.

BTW: That's true for all high-level language constructs. You could do
everything in machine language. A good language is the sum of lots of syntactic
sugar... selected with taste. :)

> You can
> abuse things the same way by writing:
> 
> class grouping:
>     def __init__(self, self.x, u_y, self.z):
>        u.y = u_y
>        del u_y
>        pass
> 
> Why is this acceptable, but your usage not?

Hmmm. Maybe this is where I'd draw the line:

  Effects of code in the *signature* must be restricted to self and locals().

self is special here because the whole purpose of the constructor is to
initialize self; otherwise you'd use a plain function. Therefore it seems more
than natural to provide special support.

> > "self" (or whatever people prefer as a name for the first argument of a
> bound
> > function) *is* special. I think therefore it deserves special support.
> 
> Yes, but is it special enough to justify adding a special case to
> another construct?

In my mind that's determined by the usage patterns as they arise in practice. A
high degree of redundancy is the worst enemy of good, readable code. The
language/framework definitely should help out here in some way.

> I'm not sure I like the idea of allowing "self.x" yet. But if you're
> going to allow it, I don't think it should be restricted.

If that's the price I have to pay for the feature I am all for it. :)
However, I feel we will get into a lot of trouble with the purists. They will
tell us that side-effects are generally vicious.

> The question is - how far are you really willing to carry this? What
> do you think of allowing arbitrary lvalues, with the assumption that
> the previous arguments are all defined (ala let*)? So you could do:
> 
> class grouping:
>     def __init__(self, x, x['abc']):
>         pass
> 
>         <mike

I am not sure this fits into the given framework. E.g.:

  from cStringIO import StringIO
  import sys

  def show(data, file_object=sys.stdout):
    print >> file_object, data

  sys.stdout = StringIO()

  show("hello, world.")

If you run this, you will see "hello, world." on the screen. This means the
right side of file_object=sys.stdout is evaluated when the Python code is
parsed/compiled, not when it is executed.

Cheers,
        Ralf




	
		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail



More information about the Python-list mailing list