Programmers Need Context Too

Apparently I’m not the only one who thinks context is vital. While most of my thoughts have to do with capturing ideas and organization, there are other areas where context is crucial. Let’s take programming for an example.

I know only enough about programming to be dangerous. (And I don’t mean dangerous in a James Bond way. I’m more like a danger to anyone who has to use the code after me. It’s not pretty.) But I do know this: to be a productive programmer of any kind, you have to have visual reference points you can quickly add and access when working through the code. Otherwise you spend most of your time trying to figure out where you are and what the heck you’re trying to do.

One way of adding more context to code is by comments. Commenting code is a great way to reference sections of code for yourself and anyone else who is going to look at it. The Rampant Coyote has a unique approach to writing code: he actually adds the comments first. Or a broader view of it could be that he adds the context of what he’s working on before he begins writing the actual code. Why?

The first benefit I gain from doing it this way is that it forces me to analyze the problem from a higher level before I start coding.

Many times we tear into our projects head first without really taking the time to assess what we’re trying to do in the first place. Often the hardest part of starting a project is figuring out what steps need to come next (or Next Actions for GTD’ers.) By clearly defining what we’re needing to do, figuring out the “how” comes much easier. After that it’s just making widgets.

Once the instructions are written out this way, writing the code itself is almost trivial. At this point, I can put my brain on auto-pilot and code away. A side benefit is that if I’m interrupted, it’s easier to eyeball what I was doing when I left off, and to pick it back up again.

How true. Adding a pinch of context instantly jogs your memory and gives you that reference point in your mind as to what you were thinking about last. But wait, there’s more.

Another advantage is that, when I am done, those little instructions to myself remain as comments for my code. When I come back to it six months and try to figure out what the heck I was thinking when I wrote the code, I’ll take a look at the comments and realize I wasn’t such an idiot after all. That does wonders for my self-esteem.

There you have it, ladies and gentlemen. Context helps you define your goals, provide a way to remember what you were working on, and boost self-esteem. But you don’t have to take my word for it. Take it from a real programmer.

Leave a Comment

{ 2 comments… add one }
  • joshua November 20, 2006, 7:21 am

    I had an instructor in college that required all our programs to contain the pseudo code as comments in the program. Of course, he also required that we wrote all the pseudo code before we started writing the program itself, so most everyone got in the habit of writing the pseudo code starting with the comment character for the language…