Don’t Repeat Yourself

DRY- of course.  One of the core principles (so I’ve read) of software development.  Repeating yourself in your code or design almost always leads to trouble- repeated bugs, fixing/editing things in multiple locations, general confusion, dogs and cats living together- pretty much all the bad parts of the Bible.

But sometimes I forget that those little machines running behind the scenes don’t really play by the rules.  Like the PHP parser.  That thing (or whoever wrote it) is way smarter than I am.  But one of its main functions is often to repeat itself (the project we’re working on makes liberal use of while loops to output content stored in the database).  So, while this program is happily doing its job, looping over rows and printing titles and text fields, repeating itself, I’m banging my head on the keyboard trying to figure out why my little jQuery ui widget is grabbing 3 elements each call instead of the one it should.

And therein lies the moral of this short Friday night story.  Throwing your css and js code into your php file while you’re developing seems like a great idea- that way, you can just work in one file, and break it out into the proper modules when everything looks right.  But be careful where, within that php file, you put your js.  Because if you accidentally put it inside one of those awesome php while loops, you’re going to end up with multiple identical functions.  And you’re gonna have a bad time.

Seriously- pretty soon I’m going to have to rename this thing to “I’m not as dumb as my code looks.”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s