Posts Tagged ‘style’

Writing and Programming

November 12th, 2008

This post is inspired by Jeff Atwoods post “Coding: It’s just writing“  Jeff argues that like writing, to code effectively is to write clear concise code.

When you’re writing on a personal blog. Very little thought goes into what you write. Much of the time, it’s almost a stream of consciousness, it’s whatever comes to your mind at the time of writing. Unless you’re a natural and experience writer with an expertise on the subject on which you’re writing, your readership will never reach an audience beyond your social circle. When you write professionally, or at least outside the personal blogging bubble, you expect to have a bigger audience, or at least an audience with higher expectations of the quality of your writing. You take more time with the choice of words, the choice of topics, the sentence structure, you have to think about what you want your audience to get out of it, you think about what your audience would like to read and whether they would like to read more of your writing afterwards. When we are reading someone elses writing, whether it’s a book, a review of a movie, or an article in the news paper, we expect certain standards or properties from each piece of writing. We unconsciously expect that the authors have considered their audiences when writing, and hope that we’re part of the audience that will find it interesting, relevant and useful.

Similarly, when you write code in the real world, you are writing it for others to read. You have an audience, those who will be maintaining your code. When we inherit someone else’s code, we hope that the authors have considered their audience and wrote code clear enough for you to understand and maintain. You hope that they have built a framework based on best practice design patterns, and that you can add to it or change it without too much effort.

When you work on a pet project, most of the time, you’re the only person who is going to read the source code, and it’s okay to take shortcuts, write ‘hacky’ code, and provide little to no internal documentation. For any non-programmers sad enough to be reading this blog(get a life!), imaging building a house and realize only after you are nearly finished that you forgot to build a bathroom. When a programming faces a analogous situation, he/she would have to write ‘hacky’ code to get around the problem by perhaps using the kitchen as a bathroom because it has similar pluming.

When you work on bigger projects, you have to think about the overall design of the system you’re building, otherwise it gets too complex to manage and you’ll be forced to use hacky programming tricks to fix and change things that will confuse those who will be reading your code later. (Imaging living in and maintaining a house with a kitchen that doubles up as a bathroom, how awkward!) When you write a book or a major essay, you have to do some top down design. It has to have some structure and planning, otherwise you’ll confuse your audience and the ideas you’re trying to present constantly changing as your mental state changes while writing.

I started blogging because I wanted practice in writing. As much as I hated English class in high school, I miss the creative writing essays — essays which I very much enjoyed writing. I chose to study computer science because I thoroughly enjoyed my first programming class in high school. Yet I’ve always thought they were very different activities. One requiring creativity, the other requiring strict logic and analysis. Only after reading Jeff’s post did I notice the similarity between the two. I’m not a natural writer, and I wouldn’t call myself a natural programmer, but I certainly find the latter much easier. Perhaps with this new realization, I can learn to write and code better at the same time.

The elements of style (a book on effective writing that inspired Jeff’s post that inspired mine) has been added to my to-read list. I’ve probably violated many advices that this book will recommend about writing, but this is still a personal blog with almost no audience base and I can still write things without much thought if I wanted to :)