Tuesday, 18 September 2012

Programming and Writing: an Analogy

My wife teaches our primary introductory programming class, CISC 121, and regularly has to advise students whether to take the even-more-introductory class first. The even-more-introductory course, CISC 101, presumes no programming experience at all. The primary course presumes "some previous experience with programming" but many students find they don't have enough such experience.

It occurred to me that there's a useful analogy to explain to students why their little bit of programming experience isn't enough for the regular course: levels of programming skill are much like levels of writing prose.

When you first learn to write, you start with the alphabet and correct spelling of words, then move on to sentences and paragraphs. Sentences have strict grammatical rules, phrases, simple sentences, and complex sentences with subordinate clauses. Stringing together a few lines of code is the programming equivalent of words, phrases, and sentences. Paragraphs have multiple sentences, single topics, and the requirement that the sentences support the topic. Just because you can write a sentence doesn't mean you can write a paragraph Coding sensible subroutines is like writing paragraphs; CISC 101 gets you to the paragraph-equivalent level.

An essay requires more paragraphs, but not just any paragraphs. The "5-paragraph essay" of high school English imposes a structure suited to beginners: an introduction with a claim about the essay topic, three paragraphs to support it, and a conclusion that ties the support paragraph to the
claim. Small multi-function programs are like essays; there's a purpose (the requirements), a few subroutines, and a main program (conclusion) that combines them to achieve the purpose. CISC 121 assumes you can write paragraphs and teaches you to write essays.

Students also have trouble understanding why introductory computing involves more than just programming. Stylistic concerns are important to both; having a consistent style makes a program easier to understand. Rhetoric (the study of how to convey meaning effectively) is a bit like both algorithm design and complexity analysis.

Higher-level computing courses, especially those involving multi-week programming projects, are like writing major essays or technical reports. You still have an introduction (requirements) and conclusion (overall processing) but also need modules (sections) each with a specific purpose that doesn't require constant references to other modules (low fan-out). You need some sort of structure to be able to find the components you're looking for, such as the hierarchy of chapters and sections (packages); you may also need indices (search functions). Technical reports are about the limit of what can be covered in undergraduate courses.

Beyond university is the Real World. "Small" programs are so large that they're more like encyclopedias: massive numbers of articles (modules) with complex relationships among them, large teams of people to create and maintain them, and content that evolves over a long time. Super-large multi-million-line programs are more like entire libraries.

I used to have a lot of trouble with "elevator conversations" trying to explain the stuff I taught (Software Engineering); the "book/encyclopedia" analogy helped a lot once I thought of it. The same has probably happened to other computer people trying to explain what they do. I'd like to think extending it downward to sentences and essays will help our undergraduates understand how our courses tie together.