Skip to content

Computer programming as an art

September 8, 2016

Computer Programming as an Art Donald Knuth, 1974

Some programs are elegant, some are exquisite, some are sparkling. My claim is that it is possible to write grand programs, noble programs, truly magnificent ones!

How do you follow David Parnas, Fred Brooks, and Tony Hoare? Perhaps with a little Donald Knuth… Today’s choice is Knuth’s 1974 Turing Award acceptance lecture, on a topic still being debated today: computer programming – art or science? As Knuth points out, you can get a hint as to where his bias lies from the title of his famous book series “The Art of Computer Programming.”

Writing in 1974, Knuth remarks that “we’ve come a long way in the last 15 years…” (1959) :

Fifteen years ago computer programming was so badly understood that hardly anyone even thought about proving programs correct; we just fiddled with a program until we “knew” it worked. At that time we didn’t even know how to express the concept that a program was correct, in any rigorous way.

Knuth’s hope that ‘fiddling until it worked’ was fading away seems to have been a little over-optimistic though. Nobody still does that today do they??? 😉

Is programming an art or science? Both says Knuth, and the two aspects complement each other.

A scientific approach is generally characterized by the words logical, systematic, impersonal, calm, rational, while an artistic approach is characterized by the words aesthetic, creative, humanitarian, anxious, irrational. It seems to me that both of these apparently contradictory approaches have great value with respect to computer programming. Emma Lehmer wrote in 1956 that she had found coding to be “an exacting science as well as an intriguing art.”

Knuth’s sense of the “art” in computer programming is an aesthetic one, of the beauty to be found in a program: “the chief goal of my work as an educator and author is to help people to learn how to write beautiful programs.”

My feeling is that when we prepare a program, it can be like composing poetry or music; as Andrei Ershov has said, programming can give us both intellectual and emotional satisfaction, because it is a real achievement to master complexity and to establish a system of consistent rules. Furthermore when we read other people’s programs we can recognize some of them as genuine works of art. I can still remember the great thrill it was for me to read the listing of Stan Poley’s SOAP II assembly program in 1958…

What constitutes a ‘good’ program in Knuth’s opinion?

  • Firstly, it’s especially good to have a program that works correctly.
  • Secondly, it is often good to have a program that won’t be hard to change, when the time for adaptation arises.

Both are these goals are easily achievable when the program is easily readable and understandable to a person who knows the appropriate language.

  • A good program must also interact gracefully with its users, especially when recovering from human errors in the input data…

It’s a real art to compose meaningful error messages or to design flexible input formats which are not error-prone.

  • Another important aspect of program quality is the efficiency with which the computer’s resources are actually being used… (And here comes the build up to one of Knuth’s best-known sayings):

I am sorry to say that many people nowadays are condemning program efficiency, telling us that it is in bad taste. The reason for this is that we are now experiencing a reaction from the time when efficiency was the only reputable criterion of goodness, and programmers in the past have tended to be so preoccupied with efficiency that they have produced needlessly complicated code; the result of this unnecessary complexity has been that net efficiency has gone down, due to difficulties of debugging and maintenance. The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.

Can every program be grand, noble, magnificent? “Sometimes we are assigned to a programming task which is almost hopelessly dull, giving us no outlet whatsover for any creativity…”

But even in such cases, there is a way to make a big improvement: it is still a pleasure to do routine jobs if we have beautiful things to work with… Therefore I want to address my closing remarks to the system programmers and the machine designers who produce the systems that the rest of us must work with. Please, give us tools that are a pleasure to use, especially for our routine assignments, instead of providing something we have to fight with.

Amen!

I will leave the closing words to the great man himself:

We have seen that computer programming is an art, because it applies accumulated knowledge to the world, because it requires skill and ingenuity, and especially because it produces objects of beauty. A programmer who subconsciously views himself (or herself) as an artist will enjoy what he (she) does and will do it better. Therefore we can be glad that people who lecture at computer conferences speak about the state of the Art.

4 Comments leave one →
  1. Francis permalink
    September 8, 2016 6:50 am

    It can be art if programmers are artists and crafts-people. As you hint, sometimes even artisans just fiddle-until-it-works.

    If programmers are cubicle-wage slaves, the result is less likely to be art, and more likely to be the-thing-that-gets-you-from-A-to-B.

    But of course, having nice tools can make “the-thing” less unpleasant to produce.

  2. Nirmalya Sengupta permalink
    September 8, 2016 8:29 am

    It is not that I don’t enjoy your posts otherwise; on the contrary, I look forward to them even if I don’t understand the topic many times. However, today’s post on Mr. Knuth’s views on this perennial debate has been particularly enjoyable. It has stayed with me for the day. Thanks.

  3. September 8, 2016 1:10 pm

    I had a boss who often repeated Knuth’s “premature optimization” quote. It was 10 years before I learned that he was quoting Knuth. See https://sparkyandsusi.wordpress.com/2015/10/10/the-root-of-all-evil/

Trackbacks

  1. Re-Blog: Programming As An Art | Transformation Through Web Development

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

%d bloggers like this: