Clarity vs. code reuse/generality
kj
no.email at please.post
Sat Jul 4 11:00:00 EDT 2009
In <7xk52p4tgg.fsf at ruckus.brouhaha.com> Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
>kj <no.email at please.post> writes:
>> sense = cmp(func(hi), func(lo))
>> if sense == 0:
>> return None
>> target_plus = sense * target + epsilon
>> target_minus = sense * target - epsilon
>> ...
>The code looks confusing to me and in some sense incorrect. Suppose
>func(hi)==func(lo)==target.
In hindsight, I too think that it is incorrect, but for a different
reason. I've rewritten it like this:
sense = cmp(func(hi), func(lo))
assert sense != 0, "func is not strictly monotonic in [lo, hi]"
I regard the very special case of func(hi)==func(lo)==target as
pathological (analogous to the fact that a stopped watch is "exactly
right" twice a day), and not one I care to support.
Thanks for your feedback!
kj
More information about the Python-list
mailing list