I Can Has Categoriez?
Oct 18, 2013
To date there have only been geography quizzes available on Brainiac Bytes (or whatever I end up deciding to call this site). This has been somewhat convenient because all of the quizzes and quiz questions neatly arrange themselves in the admin section for editing without too much confusion. However, in order to eventually have several types of quizzes covering various topics, I wanted to create a way to organize the quiz games, questions and answers to avoid them getting mixed together in an unfathomable trivial goop.
Sounds easy right? I decided that each category was going to be a separate 'object' stored on the database that has a name, parent category, and lists of quizzes and quiz questions that are in that category. My first effort only allowed two 'tiers' of categories (categories and subcategories). I soon became frustrated with this limitation though and decided to bin the idea and start again. For the system to be truly flexible, I would need to be able to add as many categories (and subcategories, and sub-subcategories and so on) as I wished. In order to do this, I would have to use recursive functions.
For those not familiar with coding, a recursive function is a function that 'calls' itself within the function, allowing for a 'loop' effect (in my case, looping through lists of lists of lists and so on). They are kind of the coding equivalent of an Escher painting. Sometimes I feel my own brain gets caught in a recursive loop trying to understand them... a problem broken only by watching cats on youtube.
With the new category system mapped out I dived into coding and made steady progress over a few days. Then, as is typical when just about to complete a large section of code, I came across a better category system that is used by Wikipedia. The main difference is that Wikipedia's system is not limited to only one 'parent' category. This provides a much more detailed and flexible (and much more complicated!) hierarchy. However, adapting my code to allow for this change would have taken considerable time, and my preference was to finish this task some time before 2015.
In the end, after quite a few days of coffee, cookies and hard work, I now have a category system up and running. Joy! Now I can finally start adding some quizzes for those people who just aren't interested in knowing the capital of Nagorno-Karabakh... whoever they are...?
Sounds easy right? I decided that each category was going to be a separate 'object' stored on the database that has a name, parent category, and lists of quizzes and quiz questions that are in that category. My first effort only allowed two 'tiers' of categories (categories and subcategories). I soon became frustrated with this limitation though and decided to bin the idea and start again. For the system to be truly flexible, I would need to be able to add as many categories (and subcategories, and sub-subcategories and so on) as I wished. In order to do this, I would have to use recursive functions.
For those not familiar with coding, a recursive function is a function that 'calls' itself within the function, allowing for a 'loop' effect (in my case, looping through lists of lists of lists and so on). They are kind of the coding equivalent of an Escher painting. Sometimes I feel my own brain gets caught in a recursive loop trying to understand them... a problem broken only by watching cats on youtube.
With the new category system mapped out I dived into coding and made steady progress over a few days. Then, as is typical when just about to complete a large section of code, I came across a better category system that is used by Wikipedia. The main difference is that Wikipedia's system is not limited to only one 'parent' category. This provides a much more detailed and flexible (and much more complicated!) hierarchy. However, adapting my code to allow for this change would have taken considerable time, and my preference was to finish this task some time before 2015.
In the end, after quite a few days of coffee, cookies and hard work, I now have a category system up and running. Joy! Now I can finally start adding some quizzes for those people who just aren't interested in knowing the capital of Nagorno-Karabakh... whoever they are...?