This will borrow my knowledge from this questionthis question, because I feel a lot of the knowledge would be the same.
First off, from when I was a freelance web programmer, using PHP and MySQL (I do not do design), a lot of the code was fairly straight forward, even the custom stuff. When I did my research in how to do something, if I could see how it would help future clients, I would not charge the full rate of researching it, and would just add the cost to the next few clients who wanted that same feature. Everyone feels like a win-win.
Is it ethical? I believe to. My time needs to be paid for, but that's not the reason you're paying me. They're paying me for my expertise. There are only a few ways to add two numbers on a computer, the most common being x += 1
. If I use this for Client A, does this mean for Client B, I need to use x = x + 1
? Does not seem logical.
The main issue is that almost everything has been done. For those that haven't been done, you are probably not the first. If you come up with a method that adds two numbers together, is flawless, and works perfectly no matter how you implement it, it's stupid to not use it. All the clients I have dealt with understand that they pay me for my expertise, not my time. I know the process, I know what works, because as a freelancer, I am the expert in my field. This is the attitude to go forward with.
The client who pays by the project does not care if it takes 5 or 10 hours, they just want it to work. If you charge $500 for the Widget Factory component, and the first time it takes you 10 hours, you're billed out at $50/hour. If you can reuse it for the next client, while still charging $500 for the component, and you can re-use old code and have it working in 5 hours, that's $100/hour you're charging! You are getting paid for your expertise, not your time.
Does the client make you sign an NDA (Non-Disclosure Agreement)? Then check to see what it covers, hopefully with a lawyer. If it's just the general idea of the project as a whole, then you should be safe keeping snippets that help you out more. Ask before signing the agreement! The last thing you want is to get in hot water with a company that could put you through court for months at a time.