Arguments For Python’s self

Bruce Eckel has perfectly articulated the rant against Python’s self parameter.

The response to arguments about self in Python is “explicit is better than implicit.” In a discussion at Pycon Brazil, I realized that we do need self in the body of a method, but being forced to place it in the argument list is redundant. I’m not actually expecting it to change, but I want to try to establish that this isn’t a dumb argument.

It is forcing the self in the parameter list of every method that irritates those who see it redundant. Guido has responded with some strong counter arguments. As usual, with so many years behind, both the sides have developed valid arguments.

I am sitting neutral, on the fence, perhaps tending to fall towards liking self. And unlike most of the arguments, mine is not about language correctness or being pythonic.

I picked up Python pretty late, coming from C, C++, Java and a bit of PHP background. By pretty late I mean when these arguments were well on there way, each side making strong points about their proposal. Unlike popular opinion, I think that self is easier for novices to understand. For programmers like me who already had the bias for the way C++ did it, self in every method did sounded silly. But in hindsight, without that bias, Python’s self seems easier to understand and explain, primarily because its place in the parameter list puts it at par with rest of them. And maybe because we can actually see it.

Also, I have not been irritated with self not being explicitly mentioned while a method is being invoked. It might be so because I am in a different mode while writing a class than consuming it, and do not mind difference in semantics. self is significant within the class, not for its consumer. And being in a different mode helps being aware of it and acknowledge it. However, I do strongly agree that the error messages about method arguments should be more accurate.

I also think that these arguments, though many of them, are significant. Though the topic is the same, each new idea brings something new in Python. Learning the internals through sincere rants is a lot easier and faster than the traditional way.

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.