Open source in first semester?

I had an interesting conversation with a colleague this past week.  He was bemoaning the lack of opportunity to get students involved in open source in their first semester.  His passion is the Linux kernel, but he's currently teaching Introduction to C Programming.

I told him about a technique I've had good success with no matter the level.  The idea for this is rooted in my English Lit. background, where reading literature is how you learn to write.  I've always been amazed that we teach people to write natural languages by having them read; but we teach people to write computer programs by having them write computer programs.  How do you grow as a developer if you never read the code of programmers better than yourself?

Let's say that you need to teach your students about something simple, take the for-loop.  How can you use open source to help you with this?  What I do is use real open source examples of the concept to show its proper (or improper) use.

Ok, so we're studying the for-loop, and we need examples.  Where to begin?  One good starting point is Google's new code search, which has open source code indexed.  Here's one way to look for for-loops in C.  Now this will produce many results that are way beyond the level of the students--you have to sift through it in order to find the right fit for your class.  However, don't let the complexity scare you: remember that you were expected to read things an order of magnitude more complex than anything you were ever asked to write in school (or did your teacher expect you to write plays at the level of Shakespeare?).

What I like about this method is that it allows you to show students that there is no magic inside the programs they use every day: apache uses for-loops, so does Mozilla, so does the Linux kernel.  Now, the stuff around that loop is beyond the scope of the class.  But if your good students are looking for a challenge, they can start reading around that loop and exploring all the things that come before and after.

Another advantage of this technique is that it helps give students the confidence to look at small parts of large source code trees without getting totally overwhelmed.  You're not trying to sit down and understand the Linux kernel; rather, you're trying to understand this for-loop right here.  Stumbling upon strange and wonderful examples of a for-loop being used is how you learn to write better for-loops yourself.  No one begins by writing for(;;).  Even though it's syntactically possible, you need to see someone do it first, you need to read it before you can write it.

I can tell you this works because I spend most of my time these days using to search for ways to do things in the Mozilla source tree.  If I couldn't read what other people wrote, I'd be completely without hope.  It may not be Shakespeare, but when it compiles, I'm not going to complain :).