Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Samples coming with SDK are intended to provide best practices. So logically it looks perfectly valid to take code from them. But usually samples come under licenses, for example a lot of samples from Microsoft are released under Microsoft Public License (MS-PL).

Samples are usually published to provide best practices and common reusable code. But how can I use code from samples if they are under rather strict licenses?

share|improve this question
What SDK are you talking about? – Adam Lear Feb 22 '11 at 15:47
@Anna Lear♦ any. Silverlight examples come under MS-PL, Android SDK are under Apache License. – Andrey Feb 22 '11 at 15:57
up vote 2 down vote accepted

I've never been in a position where I wanted to copy & paste code from a sample directly into my app. What I usually do is I read through the sample and then re-implement it in my code. I am not a lawyer, but I believe it is then my code and not subject to the sample's license. Mind you, when I say I re-implement it, I don't mean just retype straight from the SDK's help page. I study the sample until I understand it fully and then I can easily produce the code I need.

share|improve this answer

The general advice I've received (from various company and institution policies) is to never copy code without express permissions, regardless of the source. It is not just the licensing problem, but also a copyright problem and can quickly become messy and costly to sort out.

share|improve this answer

Typically, from what I have seen you end up leaving the copyrights in place and provide appropriate documentation showing where you got it from. Much like an APA citation in a paper.

share|improve this answer

As with most standardised code, leaving the copyright information in tact is a good approach and where it is dominantly visible where it's being implemented. In most cases, contacting the original development team that created the code is somewhat a bit of a hassle and something you'd rather not do. After all, the sample code is for developers to use and modify - by 'modify' I would include implement too. Why deter people from using samples?

share|improve this answer

It's like with any other source code: either meet the terms of the license or do not use the code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.