Ask HN: What do you think of reusing code you write between diferent jobs?
Code that's in production use is proven.
Conventional wisdom is that you can always improve your code, but sometimes it's already as good as it will get. I'll only rewrite code if I find I can improve it considerably. I always try to write the cleanest, best code possible, and I think I do a pretty good job at it.
Though I have been thinking that if someone competing with someone I'd already been paid to deliver code for, they could ask for (almost) the same exact features, possibly giving them a competitive advantage. I could obviously decline, but where to draw the line would be iffy.
For context, my situation is special in that I do contractual work, and all of my code remains my intellectual property, so it's all unquestionably legal. I do tell clients that I reuse my code often, though I don't go on a monologue about it. All code is written by me. This is more a question on "if you could, would you?".
8 comments
[ 2.7 ms ] story [ 29.4 ms ] threadIt usually takes some nights and weekends to get the initial body of open source code written, but since it is usually more-or-less a clone of something I've previous written and want to use again, it is fairly mindless effort.
If you're in a position where you retain the IP for what you write, (I assume you're permitted to use open source?) you could just do whatever tidyup is needed, and push it to GitHub, ready for reuse?
An employee also owns the copyright to his/her code (at least in most European countries), the company often just gains the exclusive right to use that code through the contract with the employee (or the law, in some countries). So whether or not it is you intellectual property does not matter that much, what is important is what's actually written in your freelancer contract. If you build a custom software system for a company I'd assume they will not simply let you sell "your" exact code to their competitor afterwards, at least if it's something that has some inherent competitive value (e.g. not simply an off-the-shelf solution like a CRM or website). Most companies make sure this can't happen even when working with a freelancer, so have a close look at your contract (if you have one). If there's no explicit contract it'll depend on the country you're in.
I do appreciate the word of advice, and will make sure to look out for it when I do need to sign contracts for long-term work.
It's cheaper and lower risk to hire a contractor to provide a solution to a problem when the contractor has domain knowledge, tools and code to provide a solution. Forcing him to create a solution out of whole cloth is just dumb. More expensive and comes with a much higher risk of failure and slipped deadlines. There are a ton of customers that only care that a solution was provided and have no economic interest in the software itself.
Working with a codebase you're familiar with has a few advantages. You are using a worked out API which allows you to customize it without writting yet another broken wheel API from scratch. You know where bugs are, and you often avoid exposing existing but unknown bugs due to habit[1].
[1] I learned this a along time ago watching technicians use buggy software. Over time the number of crashes and bug reports declined not because the bugs were found and fixed but because the techs unconsciously learned how to use to software in ways that didn't expose bugs.
Why can't someone re-use the knowledge they have to write code that has the desired functionality?