Puzzles

Image of a 1000-piece challenge puzzle. Thousands of pieces of glitter. Puzzles are our new hobby

I recently discovered a new hobby, puzzles. Puzzles aren’t something I particularly enjoyed as a child; maybe because the images weren’t interesting, or the quality was poor. Adulthood to the rescue, I now get to choose the puzzle, so the quality and image are both to my liking.

The first of many puzzles

Whilst watching KarenPuzzles on Youtube, I saw a puzzle which I thought looked interesting. I hit up Amazon and the next day we had the puzzle. The puzzle was solved over the holidays, the bug had not yet taken hold of us.

The bug bites

At the end of February, my Wife expressed an interest, so we purchased two more 500-piece puzzles. We got to work solving the first. Before we knew it, we were hooked, not just us but the kids as well.

A week later we had gone from owning zero adult puzzles to six. Things then got worse, we decided to step things up and move from 500-piece puzzles to 1000-peice puzzles. At the time of writing, (13th March 2023) we own six 500-piece puzzles and three 1000-piece puzzles, one of which is a challenge puzzle. I’m not sure how we’re going to find the time to complete them all but that’s another blog! We aren’t speedy solvers, we take our time, grab a drink, and start puzzling. Our solve times have so far been consistent.

1000-peice

We started our first 1000-piece last night and it looks like it is going to be a big step up from a 500-peice. It is also a more complex image than anything we have solved before. It is going to be interesting seeing how much Whisky and Disaronno is consumed before we finish.

5000-piece

I’ve already got my eye on an awesome 5000-piece puzzle, it is sitting in my wish-list waiting to be purchased. I don’t think we will be making the jump from 1000 to 5000 anytime soon. Our three-year-old enjoys helping and as much as we love that everyone enjoys our new hobby, we don’t think it is sensible to start a 5000-piece puzzle until he is a little bit older! And maybe we’ll need a bigger house!

Code Rewrite

Three wooden blocks with the words "time" "to" and "update" on them. The blocks are sitting on a white surface against a light background

I’ve discussed in a previous blog post that Budget Pro and Budget are two different Apps. I won’t repeat the rationale here, however regardless of my choice I will still need to rewrite the code for the “budget service“.

What is the budget service?

The budget service receives a collection of “budget items” from the Costs to Expect API. It is responsible for taking these budget item definitions and then creating the users Budget.

Budget items have several parameters controlling whether and how they should appear on the users Budget.

Parameter:Description:
FrequencyHow often does the budget item repeat and how does it repeat?
Start DateWhen is the budget item effective from?
End DateWhen is the budget item effective until?
AdjustmentHas the budget item been adjusted, for example value changed
PaidHas the budget item been marked as paid for the selected period?
DisabledHas the budget item been marked as disabled?
AccountWhich account does the budget item belong to?
TypeWhat is the type of the budget item, income, savings, expense etc.
Parameters that exist on budget items in Budget.

The service iterates through all the defined budget items and allocates them to each period (month) accordingly. From this, the service then calculates the projected balance for each defined account.

Why the code rewrite?

The existing budget service is serviceable. It has warts because features were added after the original design but other than me being unhappy with it, it works well enough and has tests. Me being unhappy with it is not reason enough to rewrite, we would never release anything if we kept refactoring code each time we were unhappy with it.

So, why a full code rewrite?

Well, Budget Pro is significantly more complicated that Budget. In Budget Pro we support multiple period types, many more adjustments, custom display options as well as other changes. Additionally, users can have multiple budgets meaning the service needs to know which budget it is handling as well as the permissions due to sharing features.

The original service wasn’t designed to handle custom display options let alone more advanced parameters. The budget service already feels “wrong” so although I could tack on support for all these features, I would end up with something even more clunky than now and inevitably need to rewrite it anyway.

Struggling?

What is the problem, why the need for a blog post? Well, I’m struggling, and I think I’ve worked out why.

When I created the original budget service I was working from a clean sheet. I had the data the service would use; I had a design to achieve, and I could decide how I got from A to B.

With the new service, I have a lot more baggage; I have the data, I have an updated design for the UI, I know the new features but I also have an example of a service that doesn’t work.

We all code in a specific way and this is the problem. I know what I did before isn’t right; however it does solve the problem. I could go back to basics and design from a clean sheet but that is foolish because of the existing service. As much as the existing service won’t work for Budget Pro, it has been improved over time and works and obviously, some of what it does is correct.

What am I doing?

I’m designing the new service slowly, bit by bit. I’m keeping an eye on the original service but conscious that there are many things that need to change.

The first major change is support for user options. There are multiple sections of the service that need access to user options. For example, the spend ranges for budget items, the number of ‘periods’ to display and colours. I’ve opted to use a Service Provider to register the Budget service and corresponding helper services. This makes it trivial to access the service throughout the App via the Service Container. The next issue is more parameters, specifically the more complex frequencies and more adjustments. In the original service I handled this as I iterated through the data. With a small number of parameters, this is easy but as the number of parameters grow this gets more difficult. I’m going to create data structure that manage each parameter which will hopefully help me keep the core iterating code nice and simple.

Below is a comparison image for the old and new service. As you can see the complexity has increased. However, the new service is much clearer regarding implementation.

Budget Pro and Budget "Budget" services compared. Tree structure of the two services compared, the Budget Pro services contains twice as many files/classes
The “Budget” service in Budget & Budget Pro

Will it work?

Only time can answer that but yes, I suspect everything will be fine. Yes, there will be bug fixes and there will be addons that make my eye hurt but that is working code.

A year after Budget Pro releases I will be in a better position to answer this question. I will have had to tweak things, fix many bugs, some hopefully due to scale and be working on new features. It will be at this point I will be able to say for sure if all the effort was worthwhile.