Language mavens: Is there a programming with "if then else ENDIF" syntax?

Chris Rebert clp2 at rebertia.com
Wed Nov 18 04:32:30 EST 2009


On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell <showell30 at yahoo.com> wrote:
> On the topic of "switch" statements and even-more-concise-then-we-have-
> already if/elif/else/end constructs, I have to say that Python does
> occasionally force you to write code like the code below.  Maybe
> "force" is too strong a word, but Python lends itself to if/elif
> blocks like below, which get the job done just fine, but which are not
> syntactically pretty, due to the "(el){0,1}if kind ==" duplication.
> There are often cases where if/elif statements are just a smell that
> you do not know how to do dictionary lookups, but if you converted the
> below code to use dictionary lookups, you would complicate the code
> almost as much as you abstracted the code, if not more, unless I am
> just being very naive.

I'm gonna have to disagree and say using the dictionary dispatch
technique would clean it up a good bit.
Yes, it would entail creating several functions, but those functions
could then be documented (vs. the currently opaque code blocks); and
due to their separation and smaller length, they would be easier to
understand and test than the given code.
Additionally, the sheer length of the given code segment probably
constitutes a code smell in and of itself for the function containing
that code.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list