Copyright protections extend to the expression of how the code is written. Copyright law can be used to protect code in the same way copyrights can protect a book. The original author can prevent others from copying the way the code was written. A copyright exists the very moment the expression is put into a tangible medium. As soon as the code is written a copyright exists and is vested in the person writing that code. However, a copyright must be registered to effectively sue another for copyright infringement. A patent on the other hand can be used to protect the function of the code. Patents can be used to protect the result of what the code achieves. Relying solely on copyright law may not be enough to protect your invention. There are many ways to organize and write code to produce the same result. Therefore, it is possible for someone to copy your invention without infringing your copyright. Say your invention is an app that shows where people are playing pickup basketball in your city. The copyright covering the code can prevent others from copying the exact code used for the app. Someone else could write code in a different way that also creates essentially the same app. You could not use your copyright to prevent them from making the app. Now consider that you applied for and received a patent that covers an app that shows where people are playing pickup basketball. Then someone else comes along and uses a different code that produces the same result. You could effectively use your patent to prevent them from making this app. Patents protect ideas while copyrights protect expression.