I recently was assigned the task of writing a piece of code for a very specific function.
It wasn't complicated or anything massive, but it did take a couple hours. After I completed it, I realized that there was a very similar piece of code already in the codebase.
After asking around, it turned out that my coworker who works with me and I share an office space with had already written a function for this same purpose.
In the ticket which was assigned to me, it had previously been assigned to my coworker, but they had never updated the ticket in our project management platform, to reflect the work done. Updating the ticket as soon as the work had been completed would have been standard practice in our work environment.
Basically, the project manager and my coworker had failed to communicate that this work had been done, and since the PM did not think any progress had been made, they assigned it to me.
Since I had found the old code, I asked my coworker casually if they remembered writing it. They did, and then informed me that I had 'wasted my time' rewriting it, and that I 'should have checked' before working on the ticket.
The tricky part is that my coworker is definitely my senior, and I am fairly new to this type of work, but comparing the two pieces of code side-by-side, my code accomplishes the desired effect in about 30% as many lines, and maintains a much higher level of efficiency. To be frank, my code is better in any metric.
I committed the code anyways, but I was overwhelmed by feelings that I had perhaps been passive-aggressive by submitting my code to the codebase, instead of scrapping it altogether.
I told my coworker that I had gone ahead and committed the code anyways, just to show that I had done the work assigned to me.
This was met with a very awkward back and forth between us.
It definitely made for some tense times, especially when my coworker said, "You're code looks good, but don't take it personally if I end up deleting it(and using their implementation)."
What could I have done better here? I'm pretty junior, so this was very awkward.
I just didn't want to pretend like I hadn't done the task, as then it would have looked like I had been very unproductive for the day, and reflected poorly on me.
tl;dr: lack of communication led to me doing work that had already been done. I didn't want to just hit the delete key on multiple hours of work, so I committed it anyways, leading to an awkward encounter/shift in relationship with my coworker who I work with daily.