Two minor syntactic proposals
phil hunt
philh at comuno.freeserve.co.uk
Sun Jun 17 11:39:00 EDT 2001
On Sun, 17 Jun 2001 01:53:43 +0100, Gareth McCaughan <Gareth.McCaughan at pobox.com> wrote:
>You can do it, thus:
>
> def new_method(self, x):
> something_else()
> return x+1
> Thing.new_method = new_method
>
>but that's rather ugly.
It doesn't look too bad to me. It's not as if you'd be doing it
every day, I expect. And i don't think special syntax for
operations your rarely use is a good idea -- because people
will use them too infrequently to remember the syntax.
>Every now and then we get people complaining because it's
>too easy for them to forget to include a "self" argument
>in a method definition. Every now and then, I suspect that
>most Pythonistas forget. (I certainly do.) Suppose there
>were an alternative syntax, thus:
>
> class Thing:
> def self.boring_method():
> return 0
I propose a different way of doing this: make 'self' implied in all
references to instance variables. This involves definiing 2 new keywords,
qclass and insvars. So:
qclass Thing:
insvar v, w
def myMethod(p):
print p, v, x
def otherMethod():
myMethod(1)
someFunction()
would be equivalent to:
class Thing:
def myMethod(self, p):
print p, self.v, x
def otherMethod(self):
self.myMethod(1)
someFunction()
Note that a qclass definition would have to know what its methods and instance
variables were, including those inherited from superclasses, for this to work.
Is this feasible?
Another thing i would like is multi-line comments. I know you can do this
with documentation strings, but |i find them too limiting, because you
are only allowed to put thme in certain places, and indenting rules
apply to them. I would like to be able to, in a file:
#/*
comment for MyFirstClass
...
#*/
class MyFirstClass:
...definition...
#/*
comment for MySecondClass
...
#*/
class MySecondClass:
...definition...
--
## Philip Hunt ##
## philh at comuno.freeserve.co.uk ##
More information about the Python-list
mailing list