The programming community has always had a very cooperative attitude - as Richard Stallman, founder of the Free Software Foundation said, "Sharing code is the fundamental act of friendship between programmers." This attitude has served Linux, and all programmers, very well.
If one is writing code for fun, for one's own personal enjoyment, and is planning on sending that code into the world, one has plenty of motivation to make sure that the code is correct and performs well. One's reputation as a programmer may be at stake. Which brings us to our next point.