I'm a beginner programmer who recently took on a freelance project and ended up with over 1000 lines of code. Since it was my first larger project, I didn't focus much on strict architecture initially, and now the code is complex and somewhat difficult to understand. I'm curious for insights from experienced developers: Should I refactor my code before I deliver it to the client? If so, do I charge them extra for this work? How do things typically go in the industry regarding this? Thanks for your thoughts!
4 Answers
I sometimes refactor if there’s time before the deadline. Charging extra for it? Nah! Just as I wouldn’t charge more for writing clean code in the first place, refactoring is part of the job—a necessary step to ensure it’s functional and maintainable.
If the client doesn't have technical knowledge, they're mainly interested in whether it works. So, if it does, I say just leave it as is. But, if you're going to be responsible for maintaining the code later, consider cleaning it up a bit to help your future self.
Refactoring is just rewriting the code to ensure it does the same thing, so from the patient's perspective, it should be the same deliverable. Charging extra for what’s essentially the same product seems unfair, unless the client is technical and aware of the changes needed.
Generally, refactoring is expected as part of the job, so you wouldn’t charge extra for it. It's about delivering quality code, and if the client is paying for your expertise, they expect you to finish the job well. However, how much you clean up might depend on client urgency and their budget. If they’re paying less for a quick turnaround, they get what they pay for.

Exactly! If you think you’ll be dealing with this code in the future, taking the time to tidy things up now will save you headaches later.