(snip, someone wrote)
In a legal sense, sure. Still, if someone posts a recipe for chili on a
cooking page, it seems to me the intent is to offer it to the world as in
"Here's how I make a great chili in case you want to do the same." A code
example seems like the same thing to me.
You might even be able to go into the canned chili business
with the recipe, but publishing it in a cookbook is a different
question.
But the usual thing with both recipes is to modify them, as
they say (in the recipe) to taste.
There is some explanation of this in "Numerical Recipes", but
maybe not quite good enough. Many of the programs are adapted
from others generally known, yet different enough not to
violate a previous copyright. (Or so the authors hope.)
Despite the name, it is my understanding that it is best
to use the programs as test programs for implementing the
given algorithms.
You might have a math book with an explanation of an algorithm,
but have a hard time visualizing it. With a sample program, you
can try out a few cases, see how they work, and then write your
own implementation.
I suppose a code example could just be someone showing off, as in "I
wrote this clever bit of code so I'm putting this code on a public web
page so that you can see how clever I am. But don't you dare try to use
it because if I find out you did, I'll send my lawyers after you and
make a truckload of money!" But that doesn't all that likely to me.
If it is only a few lines long, there likely aren't that many
different ways to do it. As it gets longer, there is more
possibility for variation.
In the Apple II days, there were claims that the only possible
implementation of the ROMs was the one that Apple used. The code
was so tight, using as many space-saving tricks as one could
think of, and much had to fit in a certain space, that it
might have been close to true. When you are not space or time
constrained, it is much easier to write an alternate implementation
of an algorithm, and avoid copyright problems. (Though you can
still run into patent problems.)
(snip)
I totally agree with that. If you don't know how it works, you can't fix
it if it doesn't work. You also don't know if it is going to introduce
unexpected side-effects to your code or perform horribly because the
developer of the code was only trying to show a way to do something,
not necessarily the most efficient way. Etc. etc.
And if you do know how it works, it usually isn't so hard to change
it enough to avoid copyright problems.
If I remember, there were some interesting examples in one
of the Unix suits. There are a few unix derivatives, such
as FreeBSD and NetBSD that are supposed to be reimplementations.
Someone might find something like the old C favorite:
while(*s++ = *t**) ;
in both copyright version and a derived version, and claim it
as infringement. (You might look it up for more accurate
details.) But that is so common in C programming that it
doesn't make much sense to claim copyright for it.
There are also some fun cases in literary fiction, where
one claims that another copied their story too closely.
(I believe some related to Harry Potter, where any story
with a magical boy could be considered to be infringed.)
-- glen