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.
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.