[Baypiggies] Question about breaking out of a loop

Mark Voorhies mvoorhie at yahoo.com
Wed Jun 8 02:22:14 CEST 2011

On Tuesday, June 07, 2011 05:03:26 pm Hy Carrinski wrote:
> 2. I wrote the gist in order to answer the primary question:
>     Is it an antipattern to change a datatype to cause an exception?

A different way to phrase this might be:
   What are reasonable sentinel patterns?

In Python, None is a reasonable sentinel value in a container of references,
in the same way that a null pointer is a reasonable sentinel value in C/C++.

It is also reasonable to use an exception to handle an "exceptional" case of
control flow (encountering the sentinel value), and you've shown that this
doesn't introduce overhead in Python.

So, I don't think there's anything inherently objectionable about your implementation
(comments about premature optimization notwithstanding).  It might be useful to
think of what you're doing as the special case: "marking a reference as null" 
rather than the more general and potentially hackier: "changing a datatype".


More information about the Baypiggies mailing list