Forums » Community Projects

My unfavorite antipattern

May 12, 2010 zak.wilson link
In the past two plugins I've read that were written by others, I've encountered a series of if/then statements when what they really needed was selection of an element from a table. The latter is easier to understand, easier to modify, shorter and less error-prone. I felt an irresistible urge to modify the plugins in question.

I've posted a simple example in case it's not clear what I'm talking about. It uses a basic array-like integer-indexed table, but in many cases what you actually want to do is use strings or other values as keys.
May 13, 2010 CrazySpence link
people don't have to care if you don't like it

I don't care for example

I'll keep if then'ing til the cows come home and it'll work just fine and the only thing it will annoy is pedantic people and not the computers it runs on!

yay!
May 13, 2010 ladron link
and the only thing it will annoy is pedantic people and not the computers it runs on!

Actually that isn't true. The cleaner code will in this case execute faster.