A Software Engineer and His Missing Code
There was once a software engineer refactoring legacy code.
He spent all week on it.
It was quite impressive indeed.
His architecture was lean.
His code was clean.
He was as happy as he had ever been.
Hey Software Engineer, can you fix this? The server is down!
He stashed all his code with a big frown.
But little did he know, the TS compiler was about to pull a sneaky on him.
When he pulled the latest code, the TS compiler stopped working on a whim.
Is it just for me, or is it for everyone?
Trying to find it, he ran around.
But what is this?
It compiled fine on the server.
It compiled fine for his coworker.
It compiled fine for every onlooker.
It surely must be local!
He tried clearing the cache. That didn’t mesh.
He tried upgrading Node. That didn’t bode.
Let’s nuke everything and start over!
He deletes the folder and reclones the repo.
Now the code compiles fine as it was before.
Weird but okay!
The software engineer shakes his head and plows ahead.
He works out a fix in record speed.
He got the service back to its feet.
A job well done, indeed.
He was eager to get back to his refactor.
But to his dismay, it’s no longer there.
He looked here, there, and everywhere.
But the code was nowhere.
He thought long and hard, and he finally realized.
He did not even push his code once.
He hung his head, panic-stricken.
His clean code is gone, never to be seen again.
The End
TL;DR; This happened to me. Commit and push your code often, folks.
I was working on a refactor which involved moving a domain model from RxJS-backed DataService into Redux.js. I typically work in a feature branch and commit periodically. This was one time I decided to hold off for a bit.
We released a few Ui updates over the weekend, As Monday rolled up, we received a few minor bug reports. No surprise there. I quickly fixed them up and pushed it to production.
Next up was Pull Requests. My team was hard at work, and it was time for me to release their brain-child into the wild. I typically pull their changes and run them on my local machine to make sure they’ve covered all the use cases and edge cases. Once I was satisfied, I merged their changes to master and pushed it to production.
As the final step of my routine, I pulled the latest master branch onto my machine to ensure everything was nice and green. Completely unnecessary, but hey, it makes me feel better 😃
This is when shit hit the fan. For some reason, TS is complaining it couldn’t find the module. I confirmed that the file is there and confirmed all the imports and exports are correct. Nothing is more maddening than everything that’s seemingly okay.
I figured this might just be my local environment being stale. I deleted the node_modules folder, cleared the NX cache, deleted the .angular folder, upgraded my Node version to the latest LTS, and still no luck!
It can’t just be me, right? The CI built the code just fine. We also run extensive validation on every pull request, so that’s not the case. We also religiously merge the master branch onto the feature branch to make sure there are no surprises.
Fine — so I pulled up my laptop, pulled the latest code, and it compiled just fine! WTF?
At this point, my only conclusion is I somehow borked my local setup. So I just deleted the folder (rm -rf ) and cloned the repo again. As expected, everything was working again. I have no idea why it broke in the first place, but instead of investing a few more hours to figure out what happened, I just moved on.
This is where I truly understood what I have done. I wanted to unstash my changes, but they were gone. Since they change was never pushed to remote, it was completely gone. Remember, I did rm -rf because, I am a pro like that 😃
Oh well — it’s not that bad. I did lose a few days’ worths of work, but since it’s fresh in my mind, I should be able to replicate it in a day or two. Maybe this time the code will be cleaner and leaner 😃
The moral of the story, commit AND push!