define

Marcus Alanen marcus at infa.abo.fi
Sat May 10 04:50:02 EDT 2003


On 10 May 2003 05:33:48 GMT, Bengt Richter <bokr at oz.net> wrote:
>On 9 May 2003 19:20:48 -0700, danb_83 at yahoo.com (Dan Bishop) wrote:
>>But this requires you to type 12 extra characters.  What's the advantage?
>That the actual formula line reads without line noise ;-)
>The self version sticks out even more. I.e., compare reading
>
>    self.y = (-self.b + self.sign*sqrt(self.b**2 - 4.0*self.a*self.c))/2.0*self.a
>vs
>    y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a

The usual way is to say
y = self.y
b = self.b
etc...
and then use your latter formula. Easiest to read.

>Oops, "applies to every symbol" was wrong. Good catch. Maybe '~' to exclude a symbol (or more):
>
>      with x ~ sqrt: y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a

Perhaps the other way around, use ~ for the short-name variables:
	with x: ~y = (-~b + ~sign*sqrt(~b**2 - 4.0*~a*~c))/2.0*~a
Then the common case is to just write the code, instead of escaping it with ~.
When you want to use the short-names, you explicitely say so.

Marcus





More information about the Python-list mailing list