http://qs1969.pair.com?node_id=398648


in reply to Re^2: A short, "iffy" rant
in thread A short, "iffy" rant

Yep, I agree with that, and I was referring to it. "Considered harmful" should be "considered harmful". Tongue and cheek rarely works on the internet, hence confusion.

As your if/elsif/else construct grows, the dispatch solution becomes easier to read and maintain

No doubt about it.

But what about

if ($self->hungry()) { # go eat } elsif ($theater->open() && $self->wants_movie()) { # hunger is more important than movie } elsif ($cable->has_good_tv_show()) { # watch programming shows only, of course }

Bad code, agreed ... but that doesn't translate into a dispatch table. I am quite the fan of dispatch tables.

Dispatch tables work great for scalars if you are only testing scalars, usually your conditionals are more complex.

I too, use the ternary operator most of the time (but never nested), as many things more complex imply too complex ... hence they can be redesigned ... but not always.

Sometimes efficiency is important, and sometimes an if needs to be. Heck, sometimes if you pass through once a switch is what you want (but hey, perl doesn't have a good switch that is implemented without a source filter).