Home > Python > Python without explicit self

Python without explicit self

October 28th, 2008

A month ago, Bruce Eckel wrote about wanting to remove the explicit self parameter from function argument lists in Python. Personally, I don’t mind the explicit self. To me, it makes it feel like all function objects are equal, even those that happen to be methods on classes. That said, Guido wrote an in-depth response, and I certainly recommend that you check that out if you’ve ever considered getting rid of the explicit self.

After reading Guido’s response, I assumed that there must still be some way to eliminate the need for self in Python. Python is an amazingly flexible language. Further, I assumed that somebody had already done it. And sure enough, Michael Foord wrote an article that includes a metaclass called Selfless. As I suspected, this metaclass had to resort to bytecode manipulation. You really can’t change a lot about code objects in Python. I have no intention of using Selfless myself, but the Byteplay library that Michael links to seems neat and interesting.

Python

  1. October 29th, 2008 at 05:46 | #1

    “To me, it makes it feel like all function objects are equal, even those that happen to be methods on classes. ”

    Which in Python 3, as I understand it, they indeed are. :)

  2. anonymusen
    December 10th, 2008 at 10:25 | #2

    It is obvious Guido-the-stubborn is too proud to admit this is a design flaw. And the fanboys swallow it.

  3. December 11th, 2008 at 21:38 | #3

    So, do I feed the troll? Do I delete the comment?

    You can’t just say “it’s a design flaw” without suggesting how you’d prefer things work (which requires actually reading Guido’s article).

  4. anonymusen
    December 15th, 2008 at 05:00 | #4

    Actually I did read it. In this case I would choose a shorter member variable prefix a la Ruby’s @. Guido considers this a “hack” in the article which is just silly. Easy to learn and saves lots and lots of typing and clutter. There.

    Never feed the trolls :)

  5. December 19th, 2008 at 13:09 | #5

    Hey! No fair, you were just pretending to be a troll! :)

    That’s a reasonable enough suggestion, and I’d agree that that’s no more a hack than any other syntax sugar in the language. That said, people are entitled to differences of opinion.

  1. No trackbacks yet.