It's full of empty!

My god it’s full of empty!

I read a great article on Smashing Magazine today, detailing the author’s favorite Programming Mistakes, which really highlighted just a couple of mistakes I’ve made, and seen other programmers make.

Tonight, while waiting for Chris to come home, I was working on this big WordPress plugin project I’ve been doing. Apparently I’ve been doing it for a year, based on the dates on a few files. Well, I took like 4 months off to do another one, but I digress….

The point is I found a common programming mistake that I make, and I see my fellow programmers make at work. They forget to consider the EMPTY state.

My day job is working for a 15 year old website with tons of users. Our dev systems are replicas of live data so we have lots of stuff to test against. I call this the FULL state. What we fail to consider is the EMPTY state. What happens when a user first sets up an account and is face with a blank slate? Sounds like an obvious question, right? But it’s not always.

We all start with a blank slate and program for it. But a few days/weeks/months into a project, we have been re-using that same old test account with that awesome and witty test data for Bugs Bunny, Megan Fox, or whatever your favorite mock-data is. It’s familiar and comfortable. And you blithely make changes to this stored procedure, that class or some function.

And the code gets to the next phase. Maybe it’s QA, or maybe it’s LIVE/PRODUCTION (god forbid) and the first report hits.

“Dude, when I log in/click start/add a listing, I get a massive error.”

Huh? What? It’s been working all these months fine. What could be wrong?

Well, it turns out you didn’t consider that the user (fine, intelligent user that they are) hasn’t got any data yet!

Currently, running on my test blog for just such cases, my plugin looks like this:

It's full of empty!

 

Yeah, that’s not even close to pretty. Granted the big error markers are coming from xDebug so it wouldn’t look like this to the end user normally, but still, I obviously failed to consider the empty.

So, one of my jobs this weekend is to go and rework those functions to not explode if there’s not found data, but rather to gently prompt the user to go and enter the required data.

I’ll also want to add some nag bars to the system if critical data like this is missing.

I sure hope it rains so I’m not missing anything.