A better self

Louis M. Pecora pecora at anvil.nrl.navy.mil
Mon Jul 22 18:03:05 EDT 2002


In article <mailman.1027371152.7443.python-list at python.org>, Michael
Chermside <mcherm at destiny.com> wrote:

>      # WARNING: Untested code below
> 
>      def pretendFormula(x,y,z,t):
>          return sin(t) * x**y + sqrt(z)
> 
>      def MyClass:
>          def pretend(self):
>              return pretendFormula(self.x, self.y, self.z, self.t)
> 
> Notice how this has an additional advantage... it allows you to use 
> short, simple names for the variables within the formula (the 
> traditional to write formula), while still allowing longer, more 
> descriptive names within the object

What's the overhead of the function calls versus either

(1) t, x, y, z=self.t, self.x, self.y, self.z

or

(2)t=self.t;   x=self.x;   y=self.y;   z=self.z; 

??

Seems like (1) and (2) have less overhead and someone in this thread
said (1) creates and then destroys a tuple (unnecessarily so) and (2)
is better (no intermediate tuple). 

I still prefer (1) -- most readable, but I like minimum overhead.

-- 
Lou Pecora
  - My views are my own.



More information about the Python-list mailing list