Proposal for removing self

Ian Sparks Ian.Sparks at etrials.com
Thu Aug 26 00:18:53 CEST 2004


> begin with just a period as in ".5".  What are your thoughts?

If you want to cut the typing down further you don't have to use "self" you can use :

class x:
   def __init__(s,val):
      s.val = val

   def display(s):
      print s.val

That's only one more character than your "." and it doesn't require any changes to Python. 
Of course, you'd be breaking with the tradition of naming the instance as "self" but so would your magic "." method.

If you find yourself typing "self" a lot you can also do :

s = self
s.doSomething()

Sometimes python asks us to do things that are against our sensibilities (whitespace comes to mind) but once we try it for a while we find our knee-jerk reaction to change it was simply misplaced.

Live with the language a bit, use it a bit, give python the chance to change you before you try to change python.

Use python for a week or two more and see what I mean.








> -----Original Message-----
> From: Brent W. Hughes [mailto:brent.hughes at comcast.net]
> Sent: Wednesday, August 25, 2004 6:01 PM
> To: python-list at python.org
> Subject: Proposal for removing self
> 
> 
> When doing object-oriented stuff, it bothers me to have to 
> type "self" so
> many times.  I propose that Python allow the programmer to 
> optionally type
> ".variable" instead of "self.variable" to mean the same 
> thing.  Of course,
> the interpreter would have to be more careful about detecting 
> floats that
> begin with just a period as in ".5".  What are your thoughts?
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list