But since my good buddy Alex SideBar the (AI Tool) suggested it could save me some time and trouble... I took the chance.
Let's set the scene: I am developing some stock market charts. The first and easiest thing to plot... and this took months of research to come up with was a simple Structure PricePoint.
struct PricePoint {
var timeIndex : Int
var date: Date
var value: Double
}
That timeIndex is the golden ticket... it allows a stock price to be plotted with Friday right next to Monday in the X-axis. Then you just make it look like the axis labels are dates... when in reality their not - they are an index value.
Yes, that little trick took me months of my life to learn... and you don't see it noted just everywhere - so if you want to draw stock market charts - it's worth the price of admission.
Now, much later - I'm learning all about the stock market domain - I find out that sometimes you don't want to plot ALL the data... You may just want to plot the weekly price... maybe someone smarter than you decides the weekly price will be the average closing price for the week. Easy to say, easy to understand, easy to compute... It's just easier.
So a really smart developer might just come up with a whole new class... not use PricePoint ... maybe we call it AggregatedPoint. And then add in all that extra logic for computing the averages, perhaps allowing the duration of the point to vary from days to weeks to months; and maybe even vary about hours or minutes... It can encompass so much.
Now, if you are like me, you might live for months with this dual system of PricePoint & AggregatedPoint... not knowing if one or both may be deprecated for yet another scheme - I am, after all, LEARNING.
It became obvious I needed to pick one (both was just too confusing and error prone). One of those classes had to die. I'd even written code to deal with the fact that there were two Price objects and plotting the better one was some times a choice, sometimes because of unknown factors that I don't remember but it seemed, OK, at the moment.
So I point at the files... did some quick searches... PricePoint had 200 hits in 17 files. While AggregatedPoint had way fewer... but was the richer featured class. I decided to keep AggregatedPoint (it seems like the superset). But now I had way too many places to have to rework the code (that is NOT a REFACTORING).
I asked Alex for some help in makeing a "least code changes" swap... and he/it/she came back with the Switcher-a-roo HACK using a TypeAlias to swap (in situ) the AggregatedPoint for PricePoint with...
typealias PricePoint = AggregatedPoint
Wow! OK - I'm game lets see if this is going to work out.
We had to add some extensions on AggregatedPoint to make it init() like the old PricePoint(timeIndex: Int, date: Date, value: Double) { ... }
AND we needed a few computed properties for value. Then we needed a computed property for safeDate - because of it's optionality (don't you learn to hate optionals). Turns out the original point.date and point[i].date was all over the code base ... so the safeDate hack took some work... but all less than an hour - it was done and compiling - and testing - and running!
Now I've still got to unwind the hack - but it's a proven solution. It did NOT cause the ripple effects I was dreading for so long... that caused me to procrastinate doing the SWAP. This is a HOT SWAP! A hack worth remembering.