I am trying to level up my front-end development skills as part of a plan to build a side-hustle business. In the previous posts I have been discussing my first project - howmuchisthismeetingcosting.com - a simple front-end only site for calculating the live cost of a meeting.
I was excited to finish and deploy this first project. Getting a side project - even a simple one - over the finish line is no small feat. In software development the Pareto Principle is often considered to apply: finishing the last 20% of a solution can take 80% of your effort. For a side project or a self-training project it is all too easy to avoid this overhead and quit when the project is 'good enough', but not done.
I am completely guilty of this. I am a serial project starter and rarely get something finished before I get distracted by something shiny. One of the drives behind picking a simple project was to pick a task that wouldn't be too challenging to finish, and to start trying to get out of the bad habit of abandoning projects before they are done.
This is one of the core ideas from the book 'Atomic Habits' by James Clear. To build positive habits or get rid of bad ones, start by making easy to achieve changes and do them enough that it becomes automatic. Set the cadence with easy to achieve actions and then add complexity/challenge _after_ the desired behaviour has become automatic and habitual. In my case I want to start building a habit of actually finishing projects - and one way to do this is to make sure that I start with projects that aren't overly challenging to get done.
Given all that, I was pleased to get my first project over the line.I was so excited that I couldn't wait to show it off. Look friends - I actually finished something! Cheers and Congratulations to me!
Then, about 30 seconds after trying to show the site off, a good friend of mine pointed out that the meeting cost numbers were not making any sense. The site was miscalculating the cost by a factor of around 100. The web site - which was intended to be a small blow for the cubicle worker against management bureaucracy and waste - was making it seem like pointless meetings were 100 times cheaper than they should be!
In my excitement to get something finished, I used the 'hold my beer' approach to software review and testing . The site was simple enough - and it seemed to be working - surely eyeballing it would be fine, right? Wrong.
At the heart of this website is a simple typescript class that is responsible for maintaining the running state of the meeting timer (src/components/utilities/timerstate.ts in the source). This class is a stateful service - a javascript singleton - that keeps track of the number of seconds that have elapsed in the meeting and use this to construct a string that displays the elapsed meeting cost, this string is then stored in a reactive variable that updates the HTML display.
In the original version, that was all done in a single method. The method was about 20 lines long and looked simple enough. What could go wrong? Well obviously something did.
To construct the meeting cost, I calculate the total cost of the meeting in cents, use a floor division by 100 to find the dollar component, then use the remainder to construct the cents string.
- there are no unit tests. There wasn't even a test framework installed in the project
- even if there were unit tests, this code isn't written to be well tested. It is making unpure calculations that change the state of the class, making them hard to isolate
- the variables are poorly named. if I expect the total cost to be in cents, it should be named something like 'total_cost_cents'.