Code Improvement

April 02, 2019

I have a depressing or enlightening anecdote depending on your perspective. Last week I added a new feature to a module that I thought was pretty good. I spent a few days on and off working on it. Today one of the seniors in my team submitted a PR that basically deleted my changes and rewrote pretty much the whole module. My change hadn't even made it to production yet :(. If you thought I felt like I'd been punched in the gut, you'd be right. After screaming "SERENITY NOW!", I calmed down and I took a more careful look at his changes. I'd say overall it's much cleaner than my implementation.

On a related note, one of my teammates also submitted PR that he worked long and hard on. During the code review one of the seniors found a more elegant solution and basically took a few hours to write a gem that would solve the issue. My teammate later confided to me, "I don't know whether to laugh or cry."

I guess my take from this is that if you look back on code you wrote 2 years ago it'll look like crap. The reviewers who look at your code probably have more than 2+ years experience over you. How do you think they'll feel?

The fact of the matter is there's no use worrying about whether or not what you write is perfectly optimized, idiomatic or elegant. It won't be. Focus on doing your best because that is what you're currently capable of. Improvement will come with practice, experience and good feedback.


Profile picture

Written by Yi Fei Wu who lives in Melbourne building software development teams.