32

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?

Arj
  • 539
  • 4
  • 10
  • Possible duplicate: http://programmers.stackexchange.com/questions/111434/is-it-legal-to-recreate-opensource-a-program-that-you-previously-coded-for-anothe – user Oct 07 '11 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 07 '11 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 '17 at 23:25

11 Answers11

33

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.

Thomas Owens
  • 79,623
  • 18
  • 192
  • 283
Kilian Foth
  • 107,706
  • 45
  • 295
  • 310
  • 7
    +10 (if I could) for "Don't believe us! Consult a lawyer before doing something potentially perilous." Best. Advise. Ever. – Sardathrion - against SE abuse Oct 07 '11 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 07 '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. –  Oct 07 '11 at 14:38
  • 1
    BTW - having a library of small general utility functions is usually considered a bad thing. After all, if you allow it, everyone else will have their own little utility library covering much the same ground, but with different names, parameters in different orders etc. End result - all the developers are effectively using different dialects of the language. Though I have to admit, I keep some utility libraries myself anyway. –  Oct 07 '11 at 14:41
  • 4
    @MichaelKjörling. The source you're looking for is in [Joel Spolsky's excellent answer on this subject in Start Ups](http://answers.onstartups.com/questions/19422/if-im-working-at-a-company-do-they-have-intellectual-property-rights-to-the-stu/20136#20136). – TRiG Oct 07 '11 at 17:28
  • did you mean "no, hell no"? Because the rest of your answer fits with that. Also, it would seem to be a better answer to the question than "yes, hell, yes". – psr Oct 07 '11 at 18:41
  • 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? – Andreas Bonini Oct 07 '11 at 19:26
  • 1
    @psr: The question starts "Is it *wrong* to", so "yes" means "yes, it's wrong". – Jan Hudec Oct 07 '11 at 19:45
  • @JanHudec - I see. The title is "Can I reuse code from previous jobs", so it's not clear. But I'm sure you're right about about why it's stated that way. – psr Oct 07 '11 at 20:09
  • @Kilian Foth: Right... And I agree with the concept of code written at the company being the ownership of the company. – Coyote Oct 07 '11 at 22:16
  • It also depends on the common law of the country you are in. USA, Australia, UK, and many former British colonies will mean that things done on your own time are owned by your employer as well. Usually this is moderated by "if it is in the same line of business". So if you work as a programmer during the day and design clocks by night, its not the same line of business. Selling programs that do a similar thing to your employer is shaky ground EVEN IF IT IS NOT IN YOUR EMPLOYMENT CONTRACT. IANAL but watch out. – quickly_now Oct 08 '11 at 09:39
  • @Krelp - the thing is, the people here can be expected to answer programming questions, but not really law questions. And even if we've been through the issue ourselves, we may be in an area with different laws, and our own lawyers may have simplified in such a way that - even if we remember word-perfect - we don't know the crucial difference between our situation and yours. That said, lawyers aren't magical beings. They get their information from somewhere - books, journals etc - just like humans. And you'd think we could know the laws we're subject to without bankrupting ourselves. –  Oct 08 '11 at 16:41
  • @Krelp - also, we need to cover ourselves just in case a lawyer *does* get involved. –  Oct 08 '11 at 16:44
  • @TRiG, I fail to see how that answer substantiates the statistical claim, and in any case, the statement was made as a globally valid one, as the question does not specify a jurisdiction and the answer wasn't limited to one. Before I accept it as valid, I want to see specific data to back up the claim. Otherwise, it's guesswork. – user Oct 10 '11 at 07:46
  • But what if it is an open source project eg a WordPress theme or plugin? By definition of the license, anyone can re-use the code, re-publish it, etc... so wouldn't that have to include the author (even if it was originally developed on work time)? – Drewdavid May 17 '21 at 16:56
27

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. :)

Teekin
  • 599
  • 4
  • 7
9

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.

John Straka
  • 2,313
  • 1
  • 22
  • 26
Tom Squires
  • 17,695
  • 11
  • 67
  • 88
  • 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 07 '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. – tp1 Oct 07 '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 07 '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? – Arj Oct 08 '11 at 01: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 08 '11 at 02:10
  • @tp1, ok, if it's specific to some kind of software then I see your point; because that could be interpreted as "domain specific", i.e, "why else would you write this code" – Arj Oct 08 '11 at 02:16
6

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.

Thomas Owens
  • 79,623
  • 18
  • 192
  • 283
  • 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 Thompson Oct 08 '11 at 03: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 '11 at 18:25
4

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.

psr
  • 12,846
  • 5
  • 39
  • 67
4

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. – Bruce Ediger Oct 07 '11 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. – quickly_now Oct 08 '11 at 09:37
2

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.

JeffO
  • 36,816
  • 2
  • 57
  • 124
1

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.

Mike Cellini
  • 1,865
  • 10
  • 19
1

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

jwernerny
  • 988
  • 6
  • 12
1

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.

0

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.

JimmyJames
  • 24,682
  • 2
  • 50
  • 92