#017 - Refactoring vs Perfectionism
I can be a perfectionist, which has its strength and weakness. I also see the crossover between refactoring and perfectionism, which I see as a good thing.
I have learned to curb my perfectionism with regards to everyday life. I only apply perfectionism if it's an absolute necessity - along the lines of making life easier for me. I am also using the same (subjective) principal when refactoring my code across my projects.
For example. Do I really need to write a smarty-pants function that will utilise the latest standards using very few lines of code, or do I want to write readable and maintainable code, whilst using fewer comments to describe the core functionality?
At the time of learning, I am pursuing the latter (i.e. readable and maintainable code with fewer comments).
I decided to take a week of annual leave from work, but since I work part-time, it's merely two days (not including the Bank Holiday Monday). I have since been refactoring my quiz project. I have previously refactored various functions and greatly reduced my codebase. I have revamped a core function which I can pass multiple array stacks and produce the expected results. I also resolved a lingering UX bug, as I wanted to implement visual features to support user accessibility.
The general components of my quiz project work fine. The main issue is that I can't hack the underlying game loop and it's bugging my brain.
Part of the problem relates to the array of objects that I pass the original quiz data to be randomised. This is fine, but I find myself passing extra data to functions, only for those variables not to be used at the immediate function call but carried over to another function (like a car driving alongside the highway after driving past multiple exits).
The reason for passing multiple variables and bypassing multiple exits only to use at the third function call is to (eventually) use the data due to the same index value of the generated quiz (i.e. the current question from the randomised stack).
The other reason why I feel this structure is better is because I am pulling the generated data from a function, as opposed to a global variable. Only the original quiz data is collated inside an array of objects, which I hope to convert to in JSON format - but the consensus is to deliberately avoid global variables, which I find challenging. At present, I am tinkering around with code to utilise a global variable.
My predicament is further complicated because I am using a randomly generated index value to pull data from the object array.
For example. My original quiz data is set as Q1, Q2, Q3, Q4, Q5, Q6, Q7... but I don't want to display the same order of the quiz at ever new gameplay. Because of this, I have given myself a cumbersome hurdle to jump over, but I know it will be a very rewarding gameplay for the end-user. I just to rig my randomised quiz stack with a current question counter and link it with the render question function, so it will cycle through the generated quiz stack.
Ultimately, I am refactoring a perfected game design that is stretching the grey matter in my brain, as I continue to learn the best approach to resolving this particular problem, whilst taking care to refactor code that will further accommodate design changes to the game logic, should I decide to add other new features down the pipeline.