A better self

Max M maxm at mxm.dk
Thu Jul 18 18:28:25 EDT 2002


Tom Loredo wrote:


> But the one thing that continues to irk me about the language is "self,"
> for just the reasons Huaiyu describes.  I think non-numerical programmers
> are likely not in a position to appreciate the awkwardness of "self..."
> in numerical settings, where in a many-variable expression it serves
> to hinder understanding (by making the expression very long, often
> broken across multiple lines) rather than to enhance it.  Yet I think the
> general arguments for "self" are strong and valid.  Though I often wish there
> were something like a "with" statement in such contexts, Huaiyu's
> suggestion seems like a reasonable middle ground.


I don't especially like "self" myself. But wouldn't it be easy enough to 
just:

class ProjectScheduler:

     pi = 3.14

     def setEstimatedTime(hours):
         self.estimatedTime = hours

     def calculateRealisticTime(estimatedTime):
         # rebinding vars to make the calculation easier on the eye
         pi            = self.pi
         estimatedTime = self.estimatedTime
         # the formula
         realisticTime = estimatedTime * pi
         # return result
         return realisticTime


regards Max M




More information about the Python-list mailing list