Metaphors in computer science

Thanks to Slashdot I came across the transcription of a very interesting lecture given by Edsgar Dijkstra, one of the most important computer scientists before the age of the personal computer. The lecture is interesting and a worthwhile read for anyone into computers, especially computer science education. Though there are some parts that I don’t quite agree with, one thing that struck be as being every important is the Dijkstra’s realization that computer science comes with a vast array of metaphors to help beginners and experts alike think about what it is that they are doing. Dijkstra claims that these metaphors are misguided and are very damaging to the profession.

That may very well be the case, certainly some metaphors are questionable at best. But what’s of greater concern in my opinion is that most programmers I know don’t bother to really understand the metaphors and dig under the surface of the explanations that instructors present them with. It’s fine to use a metaphor to help you think (even if that metaphor is inaccurate) as long as you know what the metaphor means, where it comes from, and how things work without the metaphor to give a simplifying abstraction.

Metaphors are just that: abstractions. They let you think about things at a higher level without being bogged down by what the actual details are. However metaphors can be problematic because they describe something unfamiliar in terms of something familiar that may actually be very different. Problems start to spring up when you expect the unfamiliar object to behave like the familiar one. Abstractions in computer science (functions, objects, interfaces etc) can be safe because you can define precisely what the abstraction’s properties are. But unless a metaphor is very carefully crafted it can easily become a leaky abstraction: one where the boundaries are undefined and weird things can happen as you approach the edges.

Take for example the desktop metaphor. It’s useful because the way windows are placed on a screen can be thought of as similar to placing papers on a desk. Files and folders also fall in rather conveniently with this idea. But what about applications? What is an application icon supposed to mean? How do you explain dragging a file onto an application’s icon to open it? This isn’t to say the desktop metaphor is bad, it’s just that it can be confusing if you interpret it literally. Some other common metaphors are:

  • A variable is a box
  • Porsche is a class and your car is an object
  • A compiler is a translator

Each of these has it’s pros and cons and some are better than others. I’ll be looking at some of these metaphors in future posts and seeing if there are ways in which they can be improved.

Advertisements

Published by

Shrutarshi Basu

Programmer, writer and engineer, currently working out of Cornell University in Ithaca, New York.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s