the annoying, verbose self
Kay Schluehr
kay.schluehr at gmx.net
Thu Nov 22 15:26:39 EST 2007
On Nov 22, 8:43 pm, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> Colin J. Williams a écrit :
>
>
>
> > bearophileH... at lycos.com wrote:
>
> >> Alexy:
>
> >>> Sometimes I
> >>> avoid OO just not to deal with its verbosity. In fact, I try to use
> >>> Ruby anywhere speed is not crucial especially for @ prefix is better-
> >>> looking than self.
>
> >> Ruby speed will increase, don't worry, as more people will use it.
>
> >> Bye,
> >> bearophile
>
> > I don't see this as a big deal, but suppose that the syntax were
> > expanded so that, in a method, a dot ".", as a precursor to an identifier,
> > was treated as "self." is currently treated?
>
> <dead-horse-beaten-to-hell-and-back>
>
> Python's "methods" are thin wrapper around functions, created at lookup
> time (by the __get__ method of the function type). What you define in a
> class statement are plain functions, period. So there's just no way to
> do what you're suggesting.
>
> </dead-horse-beaten-to-hell-and-back>
The object model is irrelevant here. The substitution is purely
syntactical and gets resolved at compile time:
def foo(first, ...):
.bar = ...
is always equivalent with:
def foo(first, ...):
first.bar = ...
and generates the same bytecode.
Whether this is helpfull, beautifull or necessary is another issue.
Kay
More information about the Python-list
mailing list