Code as rhetoric
State of the noteThere’s been a good amount of thought-dump, and some editing. There’s certainly more to say, but this will likely lay fallow for a while.
I often think of computer code as an act of rhetoric.
There is a very useful extended analogy between writing prose, and writing code. I frequently find myself talking about this, and so here it is, in written form.
The main objection to this idea is that there are some fundamental differences between prose and code. Notably, a lot of people bring up that code is created for computers, not for humans. I disagree with this.
Code is written for humans, not computers
There is no such thing as “for the computer”
Or alternatively, “Computers were made by humans”.
I think there is also a misconception that programming languages were made for computers. Even historically, they really weren’t. The act of designing and implementing a programming language is an action of humans, for humans, to further human endeavors.
There is nothing fundamental about Python. At some point, C was considered a “high-level” language. Although C does translate more straightforwardly to machine code, even that was designed by humans. So was the CPU, and the transistors that comprise it.
You’ve certainly had to read something confusing or badly written before. The grammar, spelling, and punctuation might have been perfect, but that doesn’t make it good writing. Same for code: getting it to compile or run is often only half the task.
Merely getting code to work is the same as getting the grammar right in prose. Just as writing prose is about so much more than getting the grammar right, writing code is more than getting the program to run without error.
In defense of dirty code: context matters
As readers, we all understand that there are different registers of writing. Sending a text off to a friend during a break doesn’t require the same attention to detail as an email to our boss, or a speech made to millions of people. I regularly write code that is going to be run once, on my machine, and whose only job is to change my desktop background. I sometimes write code that will be seen more often, like on this website, and I take more care. For some jobs, I was writing code that would file taxes for thousands of people, that took a different level of care.
Just like writing, code takes revising. “It works” is a very important milestone, but it is just the first milestone. In fact, this is obvious for writing: anyone who writes, also edits.
On writing good code
- Professional writers and coders write better first drafts
- There is an audience