Coding isn't always fun my friend, sometimes it's work.
Actually, I take that back. Coding is fun, engineering is work. Let me explain.
2 months ago I got a new project at work. Enable customer support to change people's plans. We sell subscriptions and sometimes folks wanna change the plan they're on.
Pfft, that's easy.
Stop old subscription, start new subscription, fiddle start dates so it looks like nothing happened. How hard can it be?
So I estimate the project line by line.
Gonna have to do this, do that, oh and we need a new UI for everything, wait what they wanna change payment methods too?? Oh shit you want to do what with refunds and credits and referral bonuses!?
I slog through the combinatorial explosion. Installment plans, plans paid once, referral credits, family discounts ... the mind recoils in horror.
16 combinations in all. Maybe more.
Estimate came out to 2 weeks. So much for easy. And here we are now 2 months later almost done.
More tests than code, 200 comments on pull requests across 4 repositories, 8 bugs from QA, 16 bugs from business, 3 years old production bugs, and I can't even count the issues I found while testing bugs. Last find was that your initial payment on a new plan never got charged. Fix took all day.
What the hell happened??
when you're going through hell, keep going
Legacy code and engineering happened my friend.
Coding is fun because you're building something from scratch. It's fast, it's free, it's beautiful. Like running in an empty green field.
You jump and frolic. You skip and hop. You sing with the sound of joy in your heart as you create something new that's never existed before and you care not if it still works tomorrow.
Engineering ... engineering is more like threading a new subway line through downtown New York.
Tall buildings that shouldn't collapse. Traffic that can't be too disrupted. Businesses that definitely have to keep running. Old subway lines you can't destroy. Sewage pipes you shouldn't touch. Internet cables you can't break. Power lines you shouldn't cut.
If you're lucky you might find dark fibre and get the secret service on your ass.
No wonder it took San Francisco almost 10 years to add 10 blocks of subway ...
Oh and while you're keeping all that old stuff alive, you're making sure the new stuff not only supports the old stuff, but keeps working for decades to come.
Tips for legacy code
Engineers love to hate on legacy code.
Look at how shitty it is. Look at how messy. Look how it uses old standards. Look how wrong it looks. What idiot wrote this.
But hear this my friend, that legacy code is paying your salary. Legacy code works
That's all you gotta keep in mind. Legacy code is legacy because it works. Your code either dies a prototype or it becomes legacy.
Do you want your code to die? No you do not.
So suck it up princess and fix that shit.
The code is there because it works. Every nook and cranny is there for a reason. Even if the reason is that you didn't know any better when you wrote it 3 years ago.
So change your mindset and rejoice!
You've got a working piece of code that just needs some love.
Whatever happened to make it look this bad – business changing their mind, engineers coming and going, or coding standards changing all around it – that code works and it pays your bills.
Do your best.
- add some tests
- update the code style
- ask business if you really absolutely still need to support that feature they asked for 3 years ago and forgot about
- remove the dead code
- consolidate messy chunks into pretty functions
- extract stuff into classes
- write some notes
- add comments
- add some tests
- then add some more tests
- make sure you add tests
- ask a friend for help
- write some docs, docs are great
- talk to stakeholders and understand the business
- write it all down
- refactor with a new approach that consolidates what the business wants now into a clean flow
- oh and write some tests
Most of all, don't stop. You're already in hell, might as well keep going until you reach the edge.
Cheers,
~Swizec
Continue reading about Famous last words: Pfft, that's easy
Semantically similar articles hand-picked by GPT-4
- Don't neglect your upgrades
- Why great engineers hack The Process
- Better is good
- Most professional engineers can't build an app from scratch
- The code is not the goal
Learned something new?
Read more Software Engineering Lessons from Production
I write articles with real insight into the career and skills of a modern software engineer. "Raw and honest from the heart!" as one reader described them. Fueled by lessons learned over 20 years of building production code for side-projects, small businesses, and hyper growth startups. Both successful and not.
Subscribe below 👇
Software Engineering Lessons from Production
Join Swizec's Newsletter and get insightful emails 💌 on mindsets, tactics, and technical skills for your career. Real lessons from building production software. No bullshit.
"Man, love your simple writing! Yours is the only newsletter I open and only blog that I give a fuck to read & scroll till the end. And wow always take away lessons with me. Inspiring! And very relatable. 👌"
Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.
Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.
Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.
Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev
Want to Stop copy pasting D3 examples and create data visualizations of your own? Learn how to build scalable dataviz React components your whole team can understand with React for Data Visualization
Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections
Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog
Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com
By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️