use of "self", was "No Do while/repeat until looping construct in python?"
William Sonna
wsonna at attglobal.net
Sun Mar 16 09:56:53 EST 2003
On Sat, 15 Mar 2003 09:07:58 -0500, Mel Wilson wrote:
> In article <pan.2003.03.15.03.25.43.800281 at attglobal.net>, "William
> Sonna" <wsonna at attglobal.net> wrote:
>>What I am sick of is getting nailed by the interpreter for forgetting to
>>add "self" to every lousy instance variable name - or even worse -
>>having it treat my omission as a local variable. The mandatory self is
>>itself a source of errors, and I believe based on my own experience that
>>it creates more errors than it prevents.
>>
>>Call it a feature if you will, but my guess is that its an
>>implementation requirement that has a side benefit for those who like
>>mandatory qualification.
>
> You choose between mandatory declaration, like in Java,
> or mandatory qualification, like in Python.
>
>
There actually is another alternative - mass qualification.
There is/(was)? a scripting lanuage that uses/(d)? the following:
::method tag
expose name address salutation
separator = 'at:'
return salutation name separator address
> Quite simply, without previous declaraion there is no
> way the language can say that what you have done is a mistake.
>
>
Precisely. The above expose statement identifies/qualifies three instance
variables in one shot. They are accessed identically to the local
variable "separator".
Overall, my opinion is that this is (marginally) superior to Python's way.
Primarily because when the inevitable omission occurs, it is remedied for
the entire method in a single, consistently located place (less-is-more
applied to qualification, you might say).
It also has a certain charm and appeal to people who like the comfort and
security of old-school declarations.
The down side is that every single method needs an expose statment. Some
might spin THAT as an upside for clarity (as many do for "self"), but it
doesn't change the fact that its a pain to repeat the same statement over
and over.
More information about the Python-list
mailing list