I work for a large software company. On the contract I'm currently working on, I have to work with a grossly inefficient legacy application that we simply don't have the budget to fix, but which is very important to our customer.
Just for fun, over the course of a few months, I wrote a new, much improved version of it at home on my own time, without using any existing code from the company's project (i.e. I own the code).
How can I get this new thing I wrote into our project? I hate working with this crappy application at work, but at the same time I don't want to necessarily give away something I wrote on my own time.
How does one bring this up to their project manager (e.g. I have this code I wrote on my own time, I'll sell you it for x dollars/some other compensation), or is this considered a frowned-upon practice? Should I expect to give away my code for free in cases like this and hope for a pat on the head?
P.S. I want to try and keep this generic, so let's assume anything I signed when I was hired, such as a non-compete, doesn't keep me from doing this kind of thing.
EDIT: I'm talking about selling my company the code, not licensing it out and supporting it on my own as my own product.
UPDATE 3/6/2009: I got in touch with SEVERAL attornies. There are a lot of legal issues with doing this, which I will explain in detail below. By worrying about these legal issues, you should have already thought about the possible repercussions outlined by many of the posters below, and decided to go ahead and sell/give away your code to either your company or your customer (I will cover all scenarios).
Problem #1: You Can Get Sued
Note that for this problem, I am referring to "customer" as the person you are selling code to, whether it is your company or your company's customer.
It was kind of funny, because one of the first things mentioned was the Bratz case; the same one that @Michael Itzoe mentioned in a comment in @Kristopher Johnson 's post (look here for details on the case). The important part of the article is this:
The ruling, issued in federal court in Riverside, followed a jury's finding that Bratz designer Carter Bryant developed the concept for the dolls while working for Mattel.
In a nutshell, I would be making myself legally vulnerable, because the customer could argue that I created this program using the knowledge from their internal proprietary systems. In my case, I could argue that, if I made the program generic enough, that it could be applied to anyone, and would only work for them with some configuration. And I might win, but I would have to deal with courts and legal fees and attorneys and taking time off to do all that, and it could end up just being a general pain in the ass. So, this is something to keep in mind.
Now, this probably wouldn't be an issue if I only wanted to sell it to the customer. They would give me a cease & desist, and I could take it to court, or just get rid of the code or whatever. But if I wanted to/started to license it out to other companies, it could end up being a big deal, especially if there's a lot of money involved. The customer would likely want a piece of that pie, and thanks to Bratz, there would be legal precedence for them getting it and shutting me down in the process.
Problem #2: If Your Customer Is The Government, You Are Fucked
I neglected to mention in my post that my customer is the government. If your client is in the private sector, then problem #2 will likely not apply to you and you can probably skip this section. However for me, this brought up some legal and bureaucratic issues.
As I found out, selling code to the government is very messy. There are conflict of interest issues between you, your company, and the government. And depending on the agency (especially if it is going on a classified network), it may need to go through a formal approval process, which, unless your code can prove that P = NP, is probably not worth the effort.
Scenario 1: Selling the government your code
Even with the problems above, this can be done. But there are a couple things to think about.
You see, the government generally doesn't just like to buy a product by itself, it wants support with it also. And if you don't want to offer that, it might be an issue. And if you do want to offer it, you may find yourself being pulled between your company and the government for your time and, depending on the complexity of your code, may actually not be physically possible given the number of hours in a day. You could hire a support person full time if you want to go that route, if the money you got was good enough.
The other issue you might face is actually getting the money. Many times the government can't alter or add money to an existing contract. So your company acting as a proxy salesman (i.e. government adding x dollars to the contract and your company giving your x dollars) may not work if the contract is fixed price. You would need to sell directly to the customer and get a check from them. The agency may or may not like this if you are "just some guy", as opposed to a company.
Scenario 2: Giving the government your code
If you decide you just want to get this code into production so you don't have to deal with the "old way" of doing things anymore, and not deal with money, this can actually a bigger problem than selling it.
I found out it is illegal to do work for the government for free. Yes, it is actually a felony to do work and not charge for it. Unless your company was paying you contract money to do this work, you can't just give it away. The only way to do this would be to open source the code under some license. However this can also lead to issues stemming from Problem #1.
NOTE: If you are an independent contractor working on a contract that exists between the company you're contracting to and that company's customer, and you are just brought in to work on it but are NOT a W2 employee of the company the contract exists with, you may be able to get away with this (again, with possible problems stemming from Problem #1).
Problem #3: The Code May Not Be Yours
As mentioned by some of the posters below, this will depend on your country's and state's individual laws, but depending on your scenario, you may not even own the rights to the code you've written. Bottom line: get a lawyer.
Conclusion
The best way to go is to get your company to pay you overtime to work on this project, and not do it on your own time, because it has the least amount of legal ramifications.
This is the route I'm going to try and go.
You will have to show your company and/or the customer that them spending extra money on you will save them x dollars. Show them the bottom line, because it's all they'll be interested in. In the case of a fixed price contract (i.e. the customer will not give you more money), the company's hourly rate for you will simply decrease to allow for you to have more hours.
In any other case where you already have something written, if you still really want to try and sell or give away your code, do not do this without an attorney, period. There are way too many issues (some of which I'm sure none of us thought of) that can come up. Keep in mind that there are a ton of different situations out there and depending on yours, as with many things, Your Mileage May Vary.