Theory Matters in Code…Who Knew? 1

What I learned on Saturday:
Just because you are copying code and just changing the variable names does not mean it will work the first time you try because, you: changed the wrong variable, forgot how you named things in your database or forgot to call the function you just wrote in your file, the debates I’m having with controlled vocabulary effect how I code.

This last one was interesting for me. I finished creating a generic function for populating my joiner database and once that was done there was nothing else I could procrastinate with before I began to build up the rest of my database. I started with my “Events” category and quickly realized that I did not need to (a) explode my array of new events because there will only ever be one new event and (b) and I did not need an array and a foreach loop for my existing events because, again, only ever going to be one. So instead of writing two if statements and having two separate functions, I created one function that checked if there was a new event and if there was created it and populated the joiner table and if there was not a new event checked if an existing event had been created and populated my joiner table and if neither was selected told me I had no event connected to this cartoon.

Easy. When I got that to work, I had decide what structure I wanted for my “Themes” and “Keywords” categories. The latter was easy and I modeled it on the code I used for my “Characters” code where I could have multiple new and/or existing keywords. But when I got that working I had to decide what code I wanted to replicate for my Themes. Did I want there to only ever be one theme per cartoon or multiple like the keywords. Like I wrote about in this other post I’ve tentatively made the decision to only have one theme per cartoon. This might change down the line but for now, I’ll see how this works when I start entering data into my “real” database.

I know I shouldn’t have been, but I was surprised to be confronted with this decision so early. In this case, it’s interesting to me as a someone studying to be a digital historian that methodological questions and the dilemma of controlled vocabulary — issues I hadn’t before associated with coding — to become relevant at this stage.

That’s what I learned on Saturday. On Sunday I learned: sometimes it’s necessary to scrap everything you’ve done to date and start all over.

This is because I began to build my “edit” page and quickly realized that the structure I had for submitting my data from my form into my database would make the edit page much more complicated — both to use and to code — than it needed to be. So, I began with the form example Fred posted on our syllabus and replicated it, changing it to suit my needs. First it was just all about getting everything in one php file and then it became all about figuring out how to get a dropdown select to prepopulate when I went to the form in “edit” mode. This was so much harder than I thought it would be and it took me the better part of a day to figure out how to do this. Part of the problem is that the form example was written in MySQLi and I’ve only been using MySQL so far. So much of my time was spent figuring out exactly what the form was doing and trying to determine if I could use the same method for some of the new things I needed to add or if I should use my older coding methods. It ended up being a combination of the two. You can read all about how I eventually got everything working and see my code here in this tutorial I wrote.

1 Comment So Far

Erin Bush says:

Sometimes scrapping it is easier, but that entire prospect seems daunting! You bring up an excellent point about the need for controlled vocabulary. I’m finding that I need to create my own data dictionary so that I can keep all my columns, functions, etc. straight. I haven’t done so yet, but before we get too far down the line, I think I may have to bite the bullet.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>