Cognitive Psychology and Computer Programming
Computer programming potentially involves understanding
(application context and possibility), planning (design), imaging
(imagination and visualization), attitude (acceptance of work
involved and confidence in completing projects), logic
(conceptualization, language use, and knowledge), creativity
(artistry) and work (persistance, exploration, purpose and
committment). It adds together small steps of progress that may
reach vast distances and a seemingly endless vista. Computer
programming involves some of the same skills as writing
(creativity, sequence, logic), offers tests as regimental as
athletics or the military (in a demanding environment) and yields
products that function as
engineered tools (manufactured objects) capable of multiplying
the effect of one who uses the programs. Computer programming
perhaps more than any other manufacturing endeavor begins with a
thought and through skilled application of knowledge yields an
intrinsically proven object that is itself almost mental (encoded
electrical information). Work that is so much a product of
thought may benefit from cognitive psychology, the study of
mental processes. Though the present report focuses on computer
programming, the applications of cognitive psychology will be
seen to benefit other mental work as well.
Introduction to Computer Programming
What does cognitive psychology have to say relative to computer
programming? Perhaps an easier formulation for beginning is, what
may a programmer hope to learn from cognitive psychology?
Cognitive psychology addresses understanding, generation of
ideas, mental effort (endurance), and ability (increase).
Application to computer programming may address the following.
- How to write programs better.
- How to write better programs (functionality and user benefit).
Uses of Cognitive Psychology in Computer Programming
One theory from psychology that is often encountered in computer
program design is George Miller's claim that humans can keep from
5 to 9 concepts in mind. One application is trying to offer
options (menus or selections) within that limit. Other capacity-related concepts include information about what tasks are easier
for people to do, providing ideas for the support of mental work,
cognitive ergonomics (making the mental environment as suitable
to workers as possible), and the implications of the fan effect
(increasing the number of ideas associated with a given cue
reduces the activation of the individual associated ideas or
nodes).
Commenting, naming, and object hierarchies have each been addressed
in the field of computer science and in books about computer
programming. Cognitive Psychology, however, brings a very
different viewpoint to the value or need for these practices.
Comments in code (description of intent of code) serve both as
an increase in semantic content of the program code and may serve
as practiced recall of meaning, so that the programmer's
understanding of the code is improved. Naming of functions,
variables, and constants within a program offers another
opportunity to increase the semantics of a program, and these
names may then better serve as cues for what the programming
elements mean. Knowledge is relative to existing knowledge and
context is important for understanding. Thus, program
organization whether at the level of functions, files, or the overall
program can improve understanding. More will be said of the
importance of the relatedness of knowledge in the sections about
association and objects.
One method that seems to be receiving more attention indicates the
relationship between knowledge elements and is called
concept mapping. The general knowledge maps of concept mapping show the functional relationship between elements. For example,
(Computer Science) --uses--> (Mathematics) --is a kind of--> (Language) --supports--> (Social Organization)
In the example the relation
of each field to another is labelled. Usually the maps have more
than one relation between a given field and other fields. The isa
and hasa relations are presently used in the theory of
object-oriented programming, and thinking about object-oriented
programming could be promoted through consideration of the
relations between human thought, semantic nets, and class
(object) hierarchies.
An expansion of the concept of knowledge can be found in the work
of Doug Lenat with the computer project Cyc. He and others
working on that project have been building a knowledge store with
the intent of giving a computer the kind of everyday data that
humans use to make decisions. The video "Thinking Machine" offers
examples of the kind of knowledge that the project has shown to
be required. One example is that one's children are always
younger than oneself.
Through theories of association, cognitive psychology brings new
focus to the idea of cues or prompts for memory of events or
semantic knowledge. Given that cues prompt knowledge, some
applications could be including cue generation in a program
(cues could be predefined from meaningful lists
such as Library of Congress call numbers for library reference
work) or strategic planning of cues. User naming of menus or
other selection options in computer programs could offer
increased association for the user between word prompts and
program functions. Other significant considerations having to do
with association relate to naming of program parts and commenting
as well as the overall design of programs (from the programming
perspective). It is important that cues be oriented toward
distinctiveness (to avoid response competition or the fan
effect), and that the relation between parts of a project
increase memory for each part. The effort that is put into naming
and other related activities can itself directly be useful for
remembering what has been named.
Cognitive psychology reveals some of the thought-related benefits
of object-orientation in computer programming. When we think of a
concept, usually associated facts will be remembered or become
available for thought at the same time. These associated thoughts
can easily be the attributes and methods of the objects. Here,
the language of attributes and methods is taken directly from
object-oriented programming. It is easier to remember discrete
details when they are integrated into higher-level ideas.
Constructing a relationship of these higher-level ideas can
increase understanding and memory for the parts. Schemas can
serve to group together process-related elements such as those
events that usually follow in sequence. One theory of cognitive
psychology holds that perception of the properties of an object
can take place without conscious effort of perception. Using that
idea with objects in programming, we see that elements related in
an object description may be more easily accessible, though such
relation (to use the theory) should be closely and evidently
related. It is possible that C++ (or other object-programming
languages) make use of concepts from psychology implicitly or
simply through using easier-to-remember methods. For example,
object hierarchies may serve as tree of cues for information
within hierarchy. In his book, "Psychology of Computer
Programming", Gerald Weinberg says, "One of the obstacles
organizations claim keeps them from moving to a new technology is
the effort required to understand the class libraries that come
with the development environments." (Weinberg, 1.i)
From observations of how the mind accomplishes mental tasks, we
may find analogies for accomplishing certain of those tasks with
computer programs. For example, in an interchange of theory and
experimentation with cognitive psychology, artificial
intelligence has defined processes like neural nets that can
become tuned for identifying relationships in data that one could
not easily define in a program. One example could be identifying
a given musician's music. Another analogy from observation of
human behavior is intelligent agents. Other possibly related
programming functions that could be related to observing mental
processes is spelling checkers that check words during writing,
light bulb comment that signals that a program has observed a use
that it may have recommendations for, schemas (outlines) for
presentations, the option of annotating online help, links in
online help, and one computer program called Mind Reader observes
word use and begins to offer previously written words in a
selection window while being used for writing.
Association is probably important for Imaging and Creativity as
well.
The theory that earlier experience unconsciously influences
behavior could be used to suggest that there may be benefit in
adding conscious review or awareness to work procedures. The
teaching of Dr. W. E. Deming shows the importance of making the
elements of thought (requirements of work) evident. He often
used the phase "how could they know?" in the context of decision-making. How will the person have knowledge to make the decision?
How will they get the knowledge? He talked about "constancy of
purpose". Make the aim a cue, then when thinking about the aim,
it is associated with benefit.
The same ideas of making the aim evident or sharing guidelines
for shared work can make programming teams more effective. Fred
Brooks talked in "The Mythical Man-Month" about how much work is
involved in communicating between members of a programming team.
These comments, though not encompassing all of cognitive
psychology's relevance for computer programming, may serve to
indicate benefit of using knowledge of mental processes while
planning and accomplishing mental work.
Edited 19 November 1998 JPF