🏡 Home👩🏽‍ About🧵 Threads

programming feels like writing

April 08, 20204 min read

Sometimes programming is lumped together with math and science. Apparently, it’s for people who are logical and ‘brainy’. While logical thinking is a component of programming, most people under-estimate how creative programming is.

I find programming similar to writing prose. Andrew thinks it’s closer to writing poetry, and Paul Graham compares programming to painting.

When you program, you need to write code that a computer can read; That’s where logical thinking comes in, because a machine only understands words based on a strict rule-based system.

However, in modern-day programming, you also need to write code that’s human readable because you and your colleagues will return to the code for years. To add new features or fix edge case bugs, you need to be able to read through the current code and understand how it’s supposed to work.

You’ll often hear programmers talk about code being ‘elegant’ or ‘concise’. What they mean is: there are many ways to write code that will functionally do the same thing. However, the particular way this code was written is easily understandable, or abstracts away complexity in an unexpected way.

Good naming is helpful here:

“Programming is basically the art of abstractions and abstractions is another way of saying names mostly. And coming up with really good names for things is a really critical piece of being able to write good software. I go to thesaurus.com probably 300 times a day. I have never actually counted, but it’s a lot of times.”

- Devon Zuegel

Another way that creating software reminds me of writing is that there’s a lot of editing. Just like in writing, you start with a messy first draft. If you’re writing a function, you first focus on getting the function to work; that is, making it computer-readable.

After the function works, you edit your code to improve conciseness and human-readability. Maybe a function you originally named `sentence` should be named, more descriptively, `replyToPuppy.` Maybe a variable called ‘string’ is not needed at all.

// Poorly named function ("sentence") and argument ("input")
// Extraneous variable "string"
function sentence(input) {
  string = `Hello ${input.name}!`
  if (input.good) {
    string = 'Good boy!'
  } else if (input.bad) {
    string = 'Bad dog.'
  return string

// Well named function ("replyToPuppy") and argument ("puppy")
// Removes extraneous string
function replyToPuppy(puppy) {
  if (puppy.good) {
    return 'Good boy!'
  } else if (puppy.bad) {
    return 'Bad dog.'
  } else {
    return `Hello ${puppy.name}!`

This is a contrived example, but the more complexity you are trying to encapsulate in your code, the more critical good editing is.

Imagine the difference between tweeting and writing a 3000-word article. You can send a tweet without much thought, but a long article requires outlining, writing, getting feedback, re-writing. A complex program is similar. You decide what you want the program to do. Then you outline how you will organize your data, what helper functions you’ll write. Then you start coding, and realize you’ve forgotten to account for edge case X, Y, and Z, and that your original plan isn’t as straightforward as you thought.

When you finally have a first draft, a co-worker edits your work; Except in programming-speak we call it ‘code review’.

How could the code be more concise? Better named? What edge cases is your code not accounting for? To continue the writing analogy, edge cases are the possible rebuttals someone might have to your article.

So the process of writing and programming feel similar to me. You are stringing together complex ideas, and that takes multiple drafts, good word choice, clarity of thought.

Programming is closer to writing than math; If you enjoy writing, you might enjoy programming;!