Two minor syntactic proposals
phil hunt
philh at comuno.freeserve.co.uk
Sun Jun 17 20:37:29 EDT 2001
On Mon, 18 Jun 2001 00:18:07 +0100, Gareth McCaughan <Gareth.McCaughan at pobox.com> wrote:
>> 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()
>
>I confess that my initial reaction is "eeurgh", which may well
>be how others react to my proposals.
Quite possibly.
Bear in mind that about half of all syntax errors I have with Python
as missing out "self"s.
> I think your qclass/insvar
>proposal breaks the following principles of Pythonic style:
>
> - "Explicit is better than implicit" (one of the timbots
> rules from way back). "self" really *is* a function argument,
> and eliminating all mention of it feels uncomfortable.
> Not to mention that "qclass" binds "self" without saying
> so. Is there anything else in Python that binds things
> that it doesn't mention? I can't think of any right now.
>
> - "No cryptic identifier names". Why "qclass"? Why not
> "xclass" or "zclass"? (Does the "q" actually stand for
> something?)
"Quick" actually.
> How easy will it be to remember that it's
> "insvar", not "instvar" or "insvars"?
good question. Perhaps "instance" or "var" would be better.
>> 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?
>
>I don't understand what you mean by "know what its instance variables
>are"; new instance variables can materialize on the fly on a per-class
>or per-instance basis.
I know that. I mean the defined ones.
>Anyway, why would it need to know that?
I was thinking in terms of a preprocessor that changes my language
(q-Python or whatever you want to call it, into python)
Say it has a line:
print x (in q-python)
It needs to know whether this means, in Python:
(1) print self.x
or
(2) print x
It all depends on whether x is a defined instance variable.
--
## Philip Hunt ##
## philh at comuno.freeserve.co.uk ##
More information about the Python-list
mailing list