Throughout my various workplaces I always wrote code which made me think "this would be really useful in other situations". Indeed, I intentionally write code, even if it takes me longer write, which I know will help me in the future (e.g. custom SubString() functions). A good candidate for these snippets are various 'Helper' classes.

These snippets I'm sure can probably be found elsewhere online but the point is, I wrote them, and I will use them again later in other jobs or for personal projects. Currently I don't maintain a personal code library, but the question is, is it wrong to take code you have produced at work and re-use it (a) for personal projects, and (b) in other jobs?

  • Possible duplicate: programmers.stackexchange.com/questions/111434/…
    – user
    Oct 7, 2011 at 13:42
  • 2
    @Michael Similar, but not an exact duplicate. The answers are very similar, but they actually are two different concerns. This one is about little snippits of code - a couple of classes, a method or two. The other is about reproducing an entire project.
    – Thomas Owens
    Oct 7, 2011 at 14:17
  • The funny thing is that I always find the flow to be in the other direction. I usually come up with the really interesting chunks of code in my hobby projects where I experiment more. Certainly nobody complains when those successful ideas make it into my for-pay work. :-)
    – DaveGauer
    Feb 27, 2017 at 23:25

11 Answers 11


I've always solved this problem by having a personal project where I put all my crazy ideas and generic stuff, and then license it under the BSD license, which allows people to re-use, alter, rebrand, close it and charge money for it. That way, I retain the copyright but can re-use the code as I please for this and that employer, so that I retain the copyright to the original, but the employer retains the copyright to the re-used instance. I figure that if they had a problem with that, then they'd simply have to pay me to rewrite it on work time which makes no sense from their point of view. Furthermore, companies use BSD code all the time, since the idea behind BSD is to allow people and companies to do with it pretty much whatever they want, including rebranding and selling it.

Then of course, if additions are made to the code at the work place, I can't re-use it elsewhere without rewriting it on my own time... which is fine because generic stuff tends to be relatively small, unless it's an idea that warrants considerable free-time effort anyway.

Writing it on your own time and licensing the code under a BSD-style license should allow you to maintain a library for yourself which you can use pretty much anywhere you want.

Now, as for contracts that claim to suck up all your personal projects' copyright... this probably differs radically between jurisdictions, but in at least some western jurisdictions it's my understanding that a contract can't do that. The contract can say that it does, but it wouldn't be enforced in a court of law because copyright has to be explicitly transferred, as opposed to "all your base are belong to us"-kinda deal which would never be upheld (in the jurisdiction where I'm from anyway). There are a number of restrictions on what can be upheld in a court of law via contract, which is why you'll usually (and hopefully) see a clause saying something to the effect that if one part of the contract doesn't work legally, the rest of the contract still holds.

But as always, consult a lawyer before you interpret this as accurate legal advice. I've never been taken to court on this so I know none of these things as lawyer-proof facts. :)


It depends on your employment contract. These days, the most probable answer is (a) yes, this is wrong and (b) yes, this is really wrong. Almost all contracts offered to developers today have provisions saying that any code you write while employed by the company (whether during office hours or not) is theirs and you automatically transfer your copyright to them. Unless you specifically negotiated against this, this presumably applies to you.

However, as always:

Don't believe us! Consult a lawyer before doing something potentially perilous.

  • 7
    +10 (if I could) for "Don't believe us! Consult a lawyer before doing something potentially perilous." Best. Advise. Ever. Oct 7, 2011 at 13:33
  • 2
    Do you have any source for the statement that "almost all contracts offered to developers" stipulate that "any code you write while employed by the company (whether during office hours or not)" belongs to the employer?
    – user
    Oct 7, 2011 at 13:41
  • 3
    These terms are routine in an employer-covering-themselves-too-much-rather-than-too-little way, and in a lot of cases, there's room for common sense. That said, (1) you need to be sure that your view of common sense agrees with theirs, and (2) it's a big risk. A few years down the line, opinions may change - especially if you're making lots of money, or if they think something you wrote might be damaging their sales. For a library of small general utility functions, it's probably easier to re-write and not have the worry. Anything more substantial and you're on very dangerous ground.
    – user8709
    Oct 7, 2011 at 14:38
  • 4
    @MichaelKjörling. The source you're looking for is in Joel Spolsky's excellent answer on this subject in Start Ups.
    – TRiG
    Oct 7, 2011 at 17:28
  • 22
    Actually.. I think it's annoying and unrealistic to always say ask a lawyer. First of all because it's common sense that you may be wrong; if you advise on how to fix a critical security vulnerability on SO you don't say "Ask a programmer!" every time. Second lawyers are expensive; honestly how many people do you think will actually hire a lawyer for asking a - usually - trivia question/curiosity? Have you ever hired a lawyer to ask something like this? Oct 7, 2011 at 19:26

Just rewrite the code as and when you need it. It completely avoids the issue for the sake of a few minutes of coding.

Chances are in the interim you will have learned more and will write something better. Rewriting code also generally makes it more elegant.

  • Agreed, but what about sub-libraries that are not simply a few minutes worth of code? Classes for accessing databases, building files, etc? True though that rewriting improves code
    – Arj
    Oct 7, 2011 at 13:58
  • 3
    It's not that simple. Any reimplementation needs to be completely different from the original code. Even rewriting it might be bad. Making a better version of existing stuff is definitely bad. It's better to keep it completely separate.
    – tp1
    Oct 7, 2011 at 18:05
  • If you develop some kind of proprietary algorithm for someone, you'd (probably) get into trouble if you wrote it again for someone else. It's a little sketchy. If it's just boilerplate code, yeah, easy enough to start a new collection.
    – user131
    Oct 7, 2011 at 19:38
  • @tp1 Hold up, what if the objective of function x() is so specific and useful that there aren't that many ways to write it? In that case, how can you keep it separate if the implementation is so similar?
    – Arj
    Oct 8, 2011 at 1:53
  • @a12jun, well, that's why it needs to be considered separately for each situation. Concept of sorting is probably programmer's existing experience in computer science, and writing that is ok. But if it's something specific which is rare or specific to some kind of software, then it's going to be bad.
    – tp1
    Oct 8, 2011 at 2:10

Depending on your terms of employment, it might be. Consult with your supervisor, human resources department, legal department, and/or ethics department to determine what is owned by your company and what is owned by you, as well as what the process is for requesting to obtain rights to use or ownership of things that you produce at work.

Nearly every place that I have worked, things that go into projects are owned by the company, but I've sought and obtained permission to bring things out for personal projects on a case-by-case basis, which usually required explaining what I want to do with it and how it wouldn't be detrimental to the organization to let it go.

  • I agree with this; talking to people at your own company is a good starting point (assuming you have a reasonably good relationship with them). It's not unlikely that they'll just say "sure, do what you like with it as long as it's not intimately related to out business". Oct 8, 2011 at 3:59
  • Yes, it is a good idea to try asking permission: the contract might say "all your base is belong to us", but that's generally just for CYA purposes, and they may well be willing to allow things that your contract doesn't guarantee. (But you might want to make sure you get it in writing, just in case.)
    – SamB
    Oct 12, 2011 at 18:25

I have had some success (not total success) at getting my employers to agree to release under an open source license some of my code written while I worked for them. Mostly code I wrote on my own time, but sometimes not. It's all code not specific to any industry.

I started the whole thing going by writing some libraries while I was unemployed, then releasing them under the MIT license. Then during the hiring process at later jobs I would mention it, and say that I would use my that code to help them, if it could, but would they mind if added things I wrote while working for them, but only things that were not specific to their business and only with their approval.

Results have varied, but I have been able to build up my library over time. And there have been cases where having the library has sped up development time for my employers.


I'm surprised that the most heavily voted answer here is "yes". As a developer, the answer has always been an "absolutely not", except in circumstances where the code is either:

  1. A previous composed library which I have developed independently of the current and all previous projects, or
  2. A library which has been made available for this purpose, e.g., open source stuff.

Somebody paid you to write the code. Barring a different understanding and agreement, which is fine, it's not right for someone else to reap the DIRECT benefits of it.

Now - the word DIRECT. If you reach the end of a project and you learned something interesting and created something useful with it that isn't directly tied up with the intellectual property of the client, take some time and create yourself a library for it. Even better - START AN OPEN SOURCE PROJECT WITH IT, so that everyone ends up wealthier for it. I think it's absolutely 100% ethically pure as the driven snow, and indeed, I've done it myself.

In the short term, reusing code you've been paid to write for someone else will cause you legal headaches. In the long run, it will cause you character headaches.

  • 1
    Bravo for answering on an ethical, rather than legal, basis. Remember: the whole of morality in not contained by the law. Also, in the USA at least, The Law has come unstuck from reality and society. The Law and Lawyers seem to actively work against the greater good. Oct 7, 2011 at 23:10
  • Fine and dandy answer but nothing to do with the law. Legally, this answer is shaky ground indeed in most western countries. Oct 8, 2011 at 9:37

I'm sure this is a legal matter depending on where you live/work and what was agreed upon/your contract.

If I learn something on my own, in my own time, all expenses paid by me (computer, internet access, software, etc.), wouldn't they want me to utilize it in my job? You find a regex for a personal project and decide to email it to your work account because you could probably use it. It would be a little silly to spend company time pretending to search for it on the internet again. Of course we strive to improve our craft, this is what is expected of programmers, blah, blah, blah, but what if it was in an area outside of programming or even IT? I can hold back if they want to play this game.

The company can try to keep a tight grip on the code I produce. It's just a poor foundation to build a relationship. If they care that much about a few lines of code, I can't imagine the extent they will go to dominate my time; which is worth a lot more.


I've had the same thoughts as well in the past. Unfortunately, I think anything you write directly for your job would technically be held under copyright by your employer. You would need to ask for permission to reuse that code in other non-company related work.

On the other hand, if you wrote code in your spare time for one of your own projects you could protect your code with some sort of copyright and then offer to give that code to your employer for use.

Either way there needs to be clear communication on the issue.

Of course, IANAL.


You question is very similar in vane to this one "Open Source - Is it legal to recreate/open source a program you previously created for another company?"

I would say you are on shaky legal grounds as the companies you worked for probably own the code you wrote for them. It would be better to code the routines from scratch, but even then there could be questions if you still had copies of the other code around.

[I'm not a lawyer, so don't expect my advise to help you in a court of law.]


I would say that those generic little method/function are best not kept between projects. Most of the time, you can use Boost or whatever your language provides to do this. Most of the time, those are better written than yours.

What is a good idea is to have a set of unit tests for those and use those to test your code kata.


I know this is an old question but someone bumped it and I felt it would be a good idea to add a reference to the very sad story of Sergey Aleynikov. Before you take any code from work, read about how doing that ruined his life and landed him in prison.

Not the answer you're looking for? Browse other questions tagged or ask your own question.