Semantics question...
Glyph Lefkowitz
glyph at twistedmatrix.com
Thu May 18 15:45:50 EDT 2000
Guido van Rossum <guido at python.org> writes:
> Excellent observation. This is indeed the origin of the "self." prefix
> requirement. But I discovered that this is actually an advantage rather
> than a problem, and I would never want to go back to Java or C++.
Speaking of Java and C++, for those of you that have to use those
languages on a regular basis, instead of using a naming convention
such as "m_", you can just follow python's lead. Much of my java code
now has an explicit "this." in front of member variables. Sure, it's
3 characters more typing, but it's a lot easier to understand if
someone else is looking at the code the first time.
(And if typing bothers you: python lets you call 'self' whatever you
like, so you can have 'm.' instead of 'm_' and have your naming
convention enforced! Although, for obvious reasons, I prefer 'self'.)
Has anyone else noticed how cool the idea of an "unbound method" is,
by the way? If I need to "borrow" some functionality, I can just grab
an unbound method and run it as a function with a different "self".
This is obviously bad form, but it helps when I'm refactoring to be
able to see *clearly* places where I needed to do that, and to be able
to do it without copying and pasting.
--
__________________________________________
| ______ __ __ _____ _ _ |
| | ____ | \_/ |_____] |_____| |
| |_____| |_____ | | | | |
| @ t w i s t e d m a t r i x . c o m |
| http://www.twistedmatrix.com/~glyph/ |
`__________________________________________'
More information about the Python-list
mailing list