















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















Thinking Ob ject-Oriented
Although the fundamental features of what we now call ob ject-oriented program- ming were invented in the 1960's, ob ject oriented languages really came to the attention of the computing public-at-large in the 1980's. Two seminal events were the publication of a widely-read issue of Byte (August 1981) that describ ed the programming language Smalltalk, and the rst international conference on ob ject-oriented programming languages and applications, held in Portland, Ore- gon in 1986. Now, almost twenty years later, it is still the case that, as I noted in the rst edition of this b o ok (in 1991):
Ob ject-oriented programming (OOP) has b ecome exceedingly p op- ular in the past few years. Software pro ducers rush to release ob ject- oriented versions of their pro ducts. Countless b o oks and sp ecial is- sues of academic and trade journals have app eared on the sub ject. Students strive to list \exp erience in ob ject-oriented programming" on their resumes. To judge from this frantic activity, ob ject-oriented programming is b eing greeted with even more enthusiasm than we saw heralding earlier revolutionary ideas, such as \structured pro- gramming" or \exp ert systems."
My intent in these rst two chapters is to investigate and explain the ba- sic principles of ob ject-oriented programming, and in doing so to illustrate the following two prop ositions:
OOP is a revolutionary idea, totally unlike anything that has come b efore in programming.
OOP is an evolutionary step, following naturally on the heels of earlier programming abstractions.
There are a numb er of imp ortant reasons why in the past two decades ob ject- oriented programming has b ecome the dominant programming paradigm. Ob ject- oriented programming scales very well, from the most trivial of problems to the most complex tasks. It provides a form of abstraction that resonates with tech- niques p eople use to solve problems in their everyday life. And for most of the dominant ob ject-oriented languages there are an increasingly large numb er of libraries that assist in the development of applications for many domains. Ob ject-oriented programming is just the latest in a long series of solutions that have b een prop osed to help solve the \software crisis." At heart, the software crisis simply means that our imaginations, and the tasks we would like to solve with the help of computers, almost always outstrip our abilities. But while ob ject-oriented techniques do facilitate the creation of complex software systems, it is imp ortant to rememb er that OOP is not a panacea. Pro- gramming a computer is still one of the most dicult tasks ever undertaken by humans; b ecoming pro cient in programming requires talent, creativity, intelli- gence, logic, the ability to build and use abstractions, and exp erience{even when the b est of to ols are available. I susp ect another reason for the particular p opularity of languages such as C++^ and Delphi (as opp osed to languages such as Smalltalk and Beta) is that managers and programmers alike hop e that a C or Pascal programmer can b e changed into a C++^ or Delphi programmer with no more e ort than the addi- tion of a few characters to their job title. Unfortunately, this hop e is a long way from b eing realized. Ob ject-oriented programming is a new way of think- ing ab out what it means to compute, ab out how we can structure information and communicate our intentions b oth to each other and to the machine. To b ecome pro cient in ob ject-oriented techniques requires a complete reevaluation of traditional software development.
\Human b eings do not live in the ob jective world alone, nor alone in the world of so cial activity as ordinarily understo o d, but are very much at the mercy of the particular language which has b ecome the medium of expression for their so ciety. It is quite an illusion to imagine that one adjusts to reality essentially without the use of language and that language is merely an incidental means of solving sp eci c problems of communication or re ection. The fact of the matter is that the `real world' is to a large extent unconsciously built up on the language habits of the group.... We see and hear and otherwise exp erience very largely as we do b ecause the language habits of our community predisp ose certain choices of interpretation." Edward Sapir (quoted in [Whorf 1956 ])
1 n
m m
t c g^ a g
z }| { t c g^ a g
z }| {
The programmer dutifully sat down and wrote a simple and straightforward FORTRAN program something like the following:
DO 10 I = 1, N-M DO 10 J = 1, N-M FOUND = .TRUE. DO 20 K = 1, M 20 IF X[I+K-1] .NE. X[J+K-1] THEN FOUND = .FALSE. IF FOUND THEN ... 10 CONTINUE
He was somewhat disapp ointed when trial runs indicated his program would need many hours to complete. He discussed his problem with a second student, who happ ened to b e pro cient in the programming language APL, who said that she would like to try writing a program for this problem. The rst student was dubious; after all, FORTRAN was known to b e one of the most \ecient" programming languages{it was compiled, and APL was only interpreted. So it was with a certain amount of incredulity that he discovered that the APL programmer was able to write an algorithm that worked in a matter of minutes, not hours. What the APL programmer had done was to rearrange the problem. Rather than working with a vector of N elements, she reorganized the data into a matrix with roughly N rows and M columns:
x 1 x 2 ... xm x 2 x 3 ... xm+ ... ... xn m ... ... xn 1 xn (m 1) ... xn 1 xn
She then ordered this matrix by rows (that is, treated each row as a unit, moving entire rows during the pro cess of sorting). If any pattern was rep eated, then two adjacent rows in the ordered matrix would have identical values.
... T G G A C C T G G A C C ...
It was a trivial matter to check for this condition. The reason the APL program was faster had nothing to do with the sp eed of APL versus FORTRAN; it was simply that the FORTRAN program employed an algorithm that was
O (M N 2 ), whereas the sorting solution used by the APL programmer required approximately O (M N log N ) op erations. The p oint of this story is not that APL is in any way a \b etter" programming language than FORTRAN, but that the APL programmer was naturally led to discover an entirely di erent form of solution. The reason, in this case, is that lo ops are very dicult to write in APL whereas sorting is trivial{it is a built-in op erator de ned as part of the language. Thus, b ecause the sorting op eration is so easy to p erform, go o d APL programmers tend to lo ok for novel applications for it. It is in this manner that the programming language in which the solution is to b e written directs the programmer's mind to view the problem in a certain way.
The assertion that the language in which an idea is expressed can in uence or direct a line of thought is relatively easy to b elieve. However, a stronger conjec- ture, known in linguistics as the Sapir-Whorf hyp othesis, go es much further and remains controversial. The Sapir-Whorf hyp othesis asserts that it may b e p ossible for an individual working in one language to imagine thoughts or to utter ideas that cannot in any way b e translated, cannot even b e understo o d, by individuals op erating in a di erent linguistic framework. According to advo cates of the hyp othesis, this can o ccur when the language of the second individual has no equivalent words and lacks even concepts or categories for the ideas involved in the thought. It is interesting to compare this p ossibility with an almost directly opp osite concept from computer science{namely, Church's conjecture. Starting in the 1930s and continuing through the 1940s and 1950s there was a great deal of interest within the mathematical and nascent computing commu- nity in a variety of formalisms that could b e used for the calculation of functions. Examples are the notations prop osed by Church [Church 1936 ], Post [Post 1936 ], Markov [Markov 1951 ], Turing [Turing 1936 ], Kleene [Kleene 1936 ] and others. Over time a numb er of arguments were put forth to demonstrate that many of these systems could b e used in the simulation of other systems. Often, such arguments for a pair of systems could b e made in b oth directions, e ectively showing that the systems were identical in computation p ower. The sheer num- b er of such arguments led the logician Alonzo Church to pronounce a conjecture that is now asso ciated with his name:
Church's Conjecture: Any computation for which there exists an e ective pro cedure can b e realized by a Turing machine.
By nature this conjecture must remain unproven and unprovable, since we have no rigorous de nition of the term \e ective pro cedure." Nevertheless, no
(^0) Section headings followed by an asterisk indicate optional material.
sp ecies
genus
family
order
class
phylum
kingdom (^) Animalia
Mollusca Chordata
Gastrop o da Reptilla (^) Mammalia
Mesogastrop o da (^) Predentata Primates
Cypraeidae Ceratopsidae (^) Hominidae
Cypraea Triceratops (^) Homo
tigris (^) horridus sapiens
QQs