Yesterday as I was working on my homework I ran into a little problem.
If you remember a few weeks ago I wrote about starting with the least common denominator of what an application is supposed to do and then building functionality on top of that.
Well, I forgot my advice. I decided instead of hitting four singles in a row to score two runs I would simply hit a home run with my first at bat.
It didn’t work out so well.
Here is how it all came to happen.
Getting My Homework – Yay!
During class yesterday we worked on connecting our simple web app to a database. The idea being that the user could add information that would extend beyond just the single instance of the program.
Well, in class, we got as far as creating new bits of information and inserting them into the database. Then we tackled the ability to delete an item… So that was cool.
Homework for the day was to convert a little app that we had written to use a database. We needed to be able to create new items and add them to the database. We also needed to be able to delete items from the database as well as edit an item that was already part of the database.
Finally once all that was working we should be able to incorporate some kind of validation. So, if an item is already in the database (or some thing like that) the system would throw an error.
Sounds easy right? 🙂
My Dilemma – Coding Out Of Control
Well, I got my database working. Connecting it to my app wasn’t terribly difficult because we had went over that specific part of things in class. Even adding the ability to add a new item to the database wasn’t too bad.
My problems started when I tried to start validating the user input. We had already done this on a local level, checking whether the user’s input was already in an array or not. So I figured I’d just refactor that bit of code and make it work… well it didn’t work, at least not how I thought it should.
Instead of checking the database for items and returning an error if there was an item already… everything was returning the error, regardless of whether it matched something already in the database. Suddenly I couldn’t add anything to my database.
I continued to hammer the anvil till around 6:30. My brain was practically fried and things weren’t making a lot of sense. I finally decided that I needed a break.
I drove home and ate some supper.
After supper I looked at the code for a little while and changed a few things, added a button but couldn’t get past the validation errors.
After awhile I just went to bed.
The New Day Brings Perspective
This morning I felt much better. My brain felt like it was actually alive and firing on all cylinders.
Once I got to the ATV I spent about an hour working on the validation stuff. However I changed how I attacked it…
Instead of trying to test the input against all of my four tests at once I had a bright idea. Why not make each test work one by one?
Like I say, it took me about an hour to get all four validations working (at least they were working at the time of this writing).
The point being that once I broke the concept of what needed to be done down into individual pieces of the puzzle (each separate validation) it wasn’t so bad. This allowed me to figure out what exactly was causing my errors to show up.
And once again… starting with the least common denominator of what needed to happen and building up from there saved my bacon.
By the way… here is basically how the app looks and works. (excuse the awful colors) If you want to look at the code it is right here on github. Should you choose to look at the code please keep in mind that I would do things differently if I was building the app now…