I have coded a project for private use. I currently have no intention for commercializing it  but the plan might change in the future. A friend of mine now wants to use it for his project, and asks if he can incorporate my code into his work.I have no idea whether he wants to commercialize his project and I do not care if he does. However, I do want to make sure that the copyright of my code still belongs to me regardless what he does with his.What is the best way to ensure and enforce this? I would rather specify everything clear, sound and upfront than getting into arguments, or worse, legal stuff later.
How to enforce copyright in source code for use by others
licensing;legal;copyright
You need to provide him with a license to use your code.The Apache license should suffice.  It provide liberal redistribution provisions, while preserving the original copyrights of all contributors, and doesn't contain a copyleft provision. Copyleft means roughly that the entity using your code must open-source their code under the same license; commercial, closed-source companies generally avoid copyleft.When you write code, you own the copyright, period (unless it is a Work for Hire).  Copyright is never transferred to anyone else, unless you explicitly transfer the copyright.  If you are an employee, it is generally assumed that you're creating a Work for Hire; the company owns the copyright.  If you are a contractor, you will generally include a provision that transfers copyright to the entity contracting you.Enforcement is a bit trickier.  You can't enforce with a license, or any other legal agreement.  All those things do is spell out the terms you expect the licensee to follow.