switch recipe?

Mark McEahern mark at mceahern.com
Fri Jul 12 16:05:42 EDT 2002


> out of curiosity, what happens when n reaches the end of the
> int/long/whatever that stores it?

My guess is this will run forever--if you let it.  <wink>

Perhaps it should allow an optional sentinel?  The assumption is the caller
is responsible for using it wisely.

> while the above code is a nice sample, the below code should not
> be given to people learning the language, it uses way too many tricks.

I appreciate your opinion and I mean and say this with respect:  One of the
joys of Python is that even supposedly advanced tricks are eminently
explorable.  I would rather not patronize someone and I'd rather make the
mistake of offering them too much than too little.  Besides, even if they
can't get it, they're not the only ones reading this list now or in the
future.    Ultimately, I can trace this sentiment back to something very
personal:  That's precisely how I'd want to be treated.  Wouldn't you?

I mean, it's not like I vomitted some obscurified black hole of
context-laden punctuation (i.e., Perl) on them.  <wink>

> Plus one letter variable names are a pain.

I go back and forth on this one.  Presumably, you don't mean for counters
and the like (e.g., i, n).  I tend to use one-letter variable names when
locals() is very small, the function is short (e.g., 5-10 lines) and the
meaning is painfully obvious.  Perhaps a bad habit?  E.g., s, imho, is
better than text or string for a string.  I'm not trying to save typing, so
much.  I strive for clarity of intent at the level of module, class,
function names.  So that I don't feel so bad using one-letter variable
names.  But, reasonable people disagree and I enjoy seeing alternative
styles, discussing them.

> switch is an interesting idea, definately needs a new name.

Maybe loop and make_loop?  At least then the danger of an infinite one is
explicit?

Thanks for the comments.

Cheers,

// mark

-






More information about the Python-list mailing list