bool v. int distinctions

Michael Geary Mike at DeleteThis.Geary.com
Sun Oct 12 11:09:23 EDT 2003


Lee Harr wrote:
> I am wondering if this is a reasonable thing to do:
>
> class Pinger:
>     def go(self, repeat=False):
>         if repeat is True:
>             repeat = -1
>         elif repeat is False:
>             repeat = 1
>         self.repeat = repeat
>         self.ping()
>
>     def ping(self):
>         while self.repeat:
>             print 'ping!'
>             if self.repeat > 0:
>                 self.repeat -= 1
>
> Won't work with 2.1, clearly, but it seems ok in a
> recent 2.2 or in 2.3.
>
> I guess my only qualm is that
>
> p = Pinger()
> p.go(repeat=0)
>
> may be a bit confusing, since it will not ping at all...
>
> What do you think?

I think the specification and test cases are missing. :-)

It is a bit unclear what you intend the code to do. What parameter types and
values can be passed to Pinger.go()? Is Pinger.ping() intended to be called
externally, or is it just an internal method used by Pinger.go()? Why is
this a class at all instead of just a function?

If you write out an exact specification, and write the test cases to go with
that, then it should become clear whether it's confusing or not.

-Mike






More information about the Python-list mailing list