DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

CodeSmells > PythonSelfClear Trail
Main /

Python Self

PythonIdioms

self is passed as the first argument... and this is exactly what happens under the covers. The object *is* passed as the first argument. The Python method definition doesn't try to hide things from you, which I consider rather good.


NO! Self *is* clarity and simplicity. It's there. Like varaible. And you can use it. Self is the total and utter non-existance of magic.
And Ruby doesn't "take care of it" as you say. Instead of writing 'self.' you write '@'. That's no more taking care of it than Python. However, what it *is* is that it introduces an additional syntax feature. In python, once you understand foobar.bla, you will also understand self.bla, and the other way around.
Besides, using @ is ugly. ;)
And as to writing self first in a method, the benefit of that is that it again is explicit and easily understandable. The code does not get a magic self, or a magick @. The only magick is that self gets passed if it's a method. And this means methods and functions can be exactly the same. And are even replaceable with each other.
No, self is a thing of beauty.





Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 08.11.2008 15:13 Uhr und seit 7. April 2005 1025 aufgerufen.