I have no class

Chris Angelico rosuav at gmail.com
Mon Nov 24 06:11:32 CET 2014


On Mon, Nov 24, 2014 at 3:21 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, 23 Nov 2014 09:02:57 -0800, Rustom Mody wrote:
>
>> Python is a bit odd in the OO-world in that it prioritizes "Explicit is
>> better than implicit" over convenience.
>>
>> Notice that you use self.throw where in most other OOP languages you
>> would use just throw.
>
> I don't think that is correct. I think that most OOP languages are like
> Python, and use a special variable to reference the current instance:
>
> In some of these languages, the use of "this/self/me" is optional, but
> I'm not aware of *any* OOP language where there is no named reference to
> the current object at all.

I believe his point is that Python, unlike every other language he can
think of, requires "self.x" instead of just "x". Every language needs
a way to say "current object", but not every language needs you to say
that for every member reference. C++, Pike, and Java let you
short-hand that. (They're all deriving from the same syntactic style
anyway.) JavaScript doesn't, I believe, although its variable scoping
rules are some of the most insane I've ever met, so there might be a
way to shortcut it. If your experience of OO is mainly from C++/Java
family languages, then yes, Python will seem odd.

ChrisA



More information about the Python-list mailing list