Python without explicit self

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.

5 thoughts on “Python without explicit self”

  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. 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).

  3. 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 🙂

  4. 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.

Comments are closed.