How to break out of two nested for loops?

Laura Creighton lac at strakt.com
Wed Jan 23 10:27:45 EST 2002


I wonder if people would use exceptions more if they had been named
something else.  I think the problem is historical.  It used to be
that the only way to write correct programs was 1. get an algorithm,
test it and make sure it works, and then 2. check, check, check, 
so that 'bad data' cannot foul your perfect program.  This gives
programs a sort of 'Platonic Ideal Form' flavour : being the
embodiment of the ideal algorithm.

When exceptions were invented, they were stuck on, like a bag, to 
existing language concepts.  And they functioned more or less to
handle emergencies, so that, again, 'bad data' cannot foul your 
perfect program.  But I do not think that this is the best way
to think of programming when using a dynamic language.

Last week or so, Michael Chermside wanted to know about Function
Overloading Without Typechecking.  But when you looked at his code,
you could tell, right off, that, what was going on in his mind was 'I
want to allow people to pass lists to my program that is really
designed to use strings, but I am deathly afraid that they will pass
bad values to my beautiful SpamThemAll'.  But the idea that there are
'bad values' is the idea that I question.  Sticking  the try: 
except AttributeError: around stuffToSpam = stuffToSpam.split() is only 
a start.  Right now, I only know that spamThemAll works on strings
because Michael Chermside said so.  But I want the gory details.
Because the very first thing I want to do is the thing that was
worrying him -- pass a not-string-or-list to spamThemAll.  I've
already got a nice class library, full of lots of objects that need
spamming.  I just need to find out what my objects need to do to be
spammable.  Will UserStrings work?  What about 2.2 newclasses based on
List and String?  Can I make them work with Sébastien Keim's fifos?
(See:  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68436)

One extremely nice thing about using python is that you don't spend
your mornings writing your 9,000th Design Pattern Adapter to get
around the type system again.  Unless, of course, somebody has
conscientiously added type-checking.  And of course, it is the
best people, who are most prone to this -- the sloppy have never
bothered checking their arguments.  Seems unfair if they get the
last laugh on us all.

Laura








More information about the Python-list mailing list