Throughout my various workplaces and through my university life I always wrote code which I thought "this would be really useful in generic situations". Indeed, I intentionally write code, even if it takes me a while to write, which I know will help me in the future (e.g. custom SubString() functions). Hence the reason for 'Helper' classes.

These functions 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 as I never have time to sit there and copy code from my work place / projects to another personal location.

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?

@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 '11 at 14:17

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.

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?
–
Michael KjörlingOct 7 '11 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.
–
Steve314Oct 7 '11 at 14:38

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?
–
Andreas BoniniOct 7 '11 at 19:26

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
–
ArjunOct 7 '11 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.
–
tp1Oct 7 '11 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.
–
Tim Post♦Oct 7 '11 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?
–
ArjunOct 8 '11 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.
–
tp1Oct 8 '11 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".
–
Keith ThompsonOct 8 '11 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.)
–
SamBOct 12 '11 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:

A previous composed library which I have developed independently of the current and all previous projects, or

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.

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.
–
Bruce EdigerOct 7 '11 at 23:10

+1,000,000 You have effectively ended this debate between Yes and No by tying in the concept of open source. If no-one shared their code (which inevitably will be done through trial and error from people's work experience) then we would not have open-source software, which is so dearly loved.
–
ArjunOct 8 '11 at 2:19

Fine and dandy answer but nothing to do with the law. Legally, this answer is shaky ground indeed in most western countries.
–
quickly_nowOct 8 '11 at 9:37

The jobs are heading to Asia so rewrite the code while the gravy train still exists. If you are getting paid to write code, write it or paste it and pretend you have rewritten it while doing something fun. Or even better, work from home and pay some more skilled, more intelligent and most importantly, much cheaper coder from Asia to write the code for you and pocket the difference. Then you can get out and enjoy the world before our corporate Gods lay us of and we are all destitute working in chip factories making chips at 2 cents an hour for wealthy Chinese and Indian iphone consumers.

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.

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'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.