I’m catching up on some long-neglected reading today, and while catching up with the latest Communications of the ACM, found this great column on “Literate Coding”. The question posed is whether or not it matters if you make spelling/grammar mistakes when writing your code. The column’s author broadens the perspective and considers things like incoherent/incomplete comments as well.
The author argues that coding is communication, but more interestingly, he lays out an argument as for whom exactly we programmers are coding (emphasis is mine):
Clear code is actually more aligned with clear writing than most people are willing to admit. Many programmers seem to have gone into their field to avoid subjects such as English or anything that would require communicating with other people rather than machines. That is unfortunate, because code is a form of human communication.
Although a computer will execute your program, it will not execute it in the exact form in which you wrote it, and it definitely does not care that your variables are misspelled or that your comments do not make it clear who did what to whom in the code that follows them. Code is not just for computers; it is for other people as well. If the next person who reads your code—in your case your professor, but after school it will be your workmates—cannot make heads or tails of it because you failed to write in a clear manner, then that is sloppy work on your part and deserves poor marks.
(As an aside, one of the more interesting “a-ha” moments in my Computer Architecture class happens when we talk about what compilers and processors do to code before executing it. Students are shocked that processors don’t execute code exactly as written, and in fact take many liberties with reordering instructions and even—horrors!—“unrolling” those loops they’ve carefully and lovingly constructed. Students tend to think, in a sense, that code is handed down on high from programmer to processor. Disabusing them of this notion is fun!)
I’ve had some interesting conversations in the past with the head of our writing program and a former dean about whether coding should be considered writing. As the author points out here, in a sense it is. As computer scientists, it’s easy to forget that code is our primary tool of communication with other computer scientists as well as with the computer. So things like structure, variable naming, and yes, comments, can either aid or hinder that communication. (Viewing code as communication may also better explain some of the holy wars developer teams wage over bracket placement and indentations—such norms are the coders’ dialects, and dealing with a dialect different from your own can be jarring!)
I’m teaching our version of CS1 and CS2 this winter, and I plan on sharing this article with both classes. I’m curious as to what kind of discussion it will engender, and whether the discussion will be fundamentally different in CS1 vs. CS2.