Thinking Object Oriented

Thinking Object Oriented

Chapter 1 Thinking Ob ject Oriented Ob ject-oriented programming has b ecome exceedingly p opular in the past few years. Soft- ware pro ducers rush to release ob ject-oriented versions of their pro ducts. Countless b o oks and sp ecial issues of academic and trade journals have app eared on the sub ject. Students strive to b e able somehow to list \exp erience in ob ject-oriented programming" on their re- sumes. To judge from this frantic activity, ob ject-oriented programming is b eing greeted with an even greater p opularity than wehave seen in the past heralding earlier revolutionary ideas, such as \structured programming" or \exp ert systems". My intent in this rst chapter is to investigate and explain the basic principles of ob ject oriented programming, and in doing so to illustrate the following two prop ositions: OOP is a revolutionary idea, totally unlikeanything that has come b efore in program- ming. OOP is an evolutionary step, following naturally on the heels of earlier programming abstractions. 1.1 Why is Ob ject-Oriented Programming Popular? To judge from much of the p opular press, the following represent a few of the p ossible reasons why Ob ject-oriented programming has, in the past decade, b ecome so p opular: The hop e that it will quickly and easily lead to increased pro ductivity and improved reliability help solve the software crises. The desire for an easy transition from existing languages. The resonant similarity to techniques of thinking ab out problems in other domains. 1 2 CHAPTER 1. THINKING OBJECT ORIENTED 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 crises". At heart, the software crises simply means that our imaginations, and the tasks wewould like to solve with the help of computers, almost always nearly outstrip our abilities. But, while ob ject-oriented techniques do facilitate the creation of complex software sys- tems, it is imp ortant to rememb er that OOP is not a \silver bullet", a term made p opular byFred Bro oks [Bro oks 87]. Programming a computer is still one of the most dicult tasks ever undertaken byhumankind; b ecoming pro cient in programming requires talent, creativity,intelligence, 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 Ob ject Pascal as opp osed to languages such as Smalltalk and Beta is that managers and programmers alikehopethataCorPascal programmer can b e changed into a C++ or Ob ject Pascal programmer with no more e ort than the addition of twocharacters to the programmer's job title. Unfortunately, this hop e is a long way from b eing realized. Ob ject- Oriented programming is a new way of thinking ab out what it means to compute, ab out how we can structure information inside a computer. To b ecome pro cient in ob ject-oriented techniques requires a complete reevaluation of traditional software development techniques. 1.2 Language and Thought \Human b eings do not live in the ob jectiveworld 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 56] This quote emphasizes the fact that the languages we sp eak in uence directly the wayin whichwe view the world. This is true not only for natural languages, such as the kind studied by the early 20th century American linguists Edward Sapir and Benjamin Lee Whorf, but also for arti cial languages such as those we use in programming computers. 1.2.1 Eskimos and Snow An almost universally cited example of the phenomenon of languages in uencing thought, although also an erroneous one see [Pullum 91] is the \fact" that Eskimo or Inuit lan- 1.2. LANGUAGE AND THOUGHT 3 guages have manywords to describ e various typ es of snow{wet, u y, heavy, icy, and so on. This is not surprising. Any community with common interests will naturally develop a sp ecialized vo cabulary for concepts they wish to discuss. What is imp ortant is to not over generalize the conclusion we can draw from this simple observation. It is not that the Eskimo eyeisinany signi cant resp ect di erent from my own, or that Eskimos can see things that I can not p erceive. With time and training I could do just as well at di erentiating typ es of snow. But the language I sp eak namely, English do es not force me into doing so, and so it is not natural to me. A di erent language such as Inuktitut thus can lead one but do es not require one to view the world in a di erent fashion. To make e ective use of ob ject oriented principles requires one to view the world in a new fashion. But simply using an ob ject oriented language such as C++ do es not, by itself, force one to b ecome an ob ject oriented programmer. While the use of an ob ject oriented language will simplify the development of ob ject oriented solutions, it is true, as it has b een quipp ed, that \FORTRAN programs can b e written in any language." 1.2.2 An Example from Computer Languages The relationship we noted b etween language and thought for natural human languages is even more pronounced in the realm of arti cial computer languages. That is, the language in which a programmer thinks a problem will b e solved will color and alter, in a basic fundamental way, the fashion in which an algorithm is develop ed. An example will help illustrate this relationship b etween computer language and problem solution. Several years ago a studentworking in genetic researchwas faced with a task involved in the analysis of DNA sequences. The problem could b e reduced to a relatively simple form. The DNA is represented as a vector of N integer values, where N is very large on the order of tens of thousands. The problem was to discover whether any pattern of length M, where M was a xed and small constant say ve or ten is ever rep eated in the vector of values. ACTCGGATCTTGCATTTCGGCAATTGGACCCTGACTTGGCCA ... 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 4 CHAPTER 1. THINKING OBJECT ORIENTED The studentwas somewhat disapp ointed when trial runs indicated his program would need signi cantly 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. The second student said that she would like to try writing a program for this problem. The rst studentwas dubious. After all, FORTRAN was known to b e one of the most \ecient" programming languages. It was compiled, after all, and APL was only interpreted. Therefore it was with a certain amount of incredulity that he discovered 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 work- ing with a vector of N elements, she reorganized the data into a matrix with roughly N rows and M columns: A C T C G G p ositions 1 to M C T C G G A p ositions 2 to M +1 T C G G A T p ositions 3 to M +2 C G G A T T p ositions 4 to M +3 G G A T T C p ositions 5 to M +4 G A T T C T p ositions 6 to M +5 . T G G A C C G G A C C C . The APL programmer then sorted this matrix byrows. If any pattern was rep eated, then two adjacentrows in the sorted 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, but was simply b ecause 2 the FORTRAN program employed an algorithm that was O M N , 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 to indicate that APL is in anyway a \b etter" programming language than FORTRAN, but to ask whyitwas that the APL programmer was naturally led to discover a b etter solution.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    26 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us