define
Bengt Richter
bokr at oz.net
Sat May 10 10:27:18 EDT 2003
On 10 May 2003 11:50:02 +0300, marcus at infa.abo.fi (Marcus Alanen) wrote:
>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...
Ok, let's do the whole deal ;-)
b = self.b
sign = self.sign
a = self.a
c = self.c
y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
self.y = y
vs
with self ~ sqrt:
y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
>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
I guess I don't understand what you mean by "other way around." ISTM you just
reintroduced the line noise again. The point of '~' was to fix a single exception
or two to the implicit designation of 'every' symbol.
>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.
But the reason for using a 'with x ~ sqrt:' in the first place would be
that that "common case" was not "common" at all in that context ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list