switch

Carl Banks pavlovevidence at gmail.com
Thu Dec 10 08:25:45 EST 2009


On Dec 10, 3:34 am, Asun Friere <afri... at yahoo.co.uk> wrote:
> On Dec 10, 2:00 pm, Carl Banks <pavlovevide... at gmail.com> wrote:

[snip most of questionable, verly verbose reply]

> > You argued that a decent language OO should never
> > have a switch statement because polymorphic dispatch is the right way
> > to handle it in OO languages, which implies that polymorphism can and
> > should take the place of any switch statement.
>
> That is a misreading.  I wrote, that the case logic is "probably"
> symptomatic of poor design. I advocated "considering" whether an OO
> solution might be more appropriate.  You misunderstand my intent.  I'm
> not here to postulate some ultimate OO truths, but to provide
> practical advice (aimed here mainly at Hong and Kee).  In regard elif
> chains, this is my advice.

Even granting that your post wasn't as drastic as it sounded (and
enough people reacted to your first post that you should should
"probably" "consider" whether it came off a little more strongly than
you intended), I think you are still overstating it by a lot.

OO polymorphic dispatching is good for some stuff, and simpler
dispatching such with if...else, a dict, or a hypotheical switch, is
good for some stuff.  That's it.  Having a bunch of if...elses is not
"probably" wrong, and it's not a red flag, unless you're not a good
programmer and have already missed a bunch of other more pertinent red
flags.


Carl Banks



More information about the Python-list mailing list