Sather Provides Nonproprietary Access to Object-Oriented Programming
Total Page:16
File Type:pdf, Size:1020Kb
OBJECT-ORIENTED PROGRAMMING Sather Provides Nonproprietary Access to Object-Oriented Programming Stephen M. Omohundro Sather supports strong typing, garbage collection, object-oriented dispatch, multiple inheritance, and parameterized types odern scientific com ware components. More and more oped to meet the needs of research puting is placing ever models use complex graph-based projects at the International Comput more stringent re structures such as neural networks er Science Institute (lCSI) , which quirements on the au for some portion of the representa required a simple, efficient, nonpro thors of scientific code, tiop. These tasks are far more like prietary, object-oriented language. and on the languages general-purpose computing than tra ICSI is involved in several areas that and programming environments that ditional scientific computing. The require the construction of complex they use. At one time, most scientists appropriate software tools are corre software for computationally inten were happy with systems that could spondingly more like the tools devel sive tasks. Examples include a gen efficiently execute relatively simple oped for general-purpose tasks. eral-purpose connectionist simulator, repetitive operations on fixed-sized Object-oriented programming a high-level vision system based on arrays. The tools appropriate for that has been one of the most notable complex geometric data structures, task are woefully inadequate for the recent developments in modern pro the support software for a high-speed challenges posed by the computa gramming languages. Unfortunately, paranel computing engine for speech tional sophistication of recent algor it is often associated with reduced recognition, and CAD tools for inte ithms for scientific computing. computational efficiency, and so has grated-circuit design. Such challenges take many not seemed appropriate for scientific We investigated several existing forms. For example, modern finite computing. This article describes a languages, including C++,6 Objec element code must adaptively change new language, "Sather," which was tive C,7 Eiffel,4,s Self,S Smalltalk,9 the structure of the underlying grid, designed to retain the powerful bene and CLOS.IO Only C++ was effi dynamically adding and deleting fits of object-oriented programming cient enough for our needs, but its nodes during a computation. Com without sacrificing efficiency.I,2,3 overall complexity and lack of gar plex geometry algorithms are re Sather was derived from the bage collection, object type tags quired for efficient manipulation and language Eiffel,4,5 and is designed to (needed for persistency and object visualization of geometric structures. be very efficient and simple, while distribution), and parameterized Modern nonlinear optimization tech supporting object-oriented dispatch, types, led us to begin our work with niques utilize many interacting soft- strong typing, mUltiple inheritance, Eiffel. Our experience with Eiffel parameterized types, garbage collec allowed us to identify the features Stephen M. Omohundro is a research scientist at The International Computer Science Institute. tion, and a clean syntax. Each of these that were essential for our purposes. 1947 Center Sr.. Suite 600. Berkeley, CA 94704; aspects will be described in turn in We required a nonproprietary com e-mail: [email protected]. this article. Sather was initially devel piler, however, to serve as a base for 444 COMPUTERS IN PHYSICS. VOL 6. NO.5. SEP/OCT 1992 Physics Academic - develeping a parallel object-oriented classes. This can simplify the debug language to run on new experimental ging process tremendously, and lead Software parallel hardware. to far greater reliability. Sather was developed to incorpo It is important to understand the PEER-REVIEWED rate the features of Eiffel that were benefits that object-oriented pro EDUCATIONAL SOFTWARE essential to us as well as others aimed gramming gives over traditional sub Published by the American Institute of Physics at enhancing efficiency and simpli routine libraries, which also aim to in cooperation with city. The initial Sather compiler was support reuse. A subroutine library American Physical Society written in Sather over the summer of makes it easy for newly-written code American Association ofPhysicB Teachers 1990. The compiler generates porta to make calls on old code, but does ble C code and links easily with not make it easy to get old code to call SCOIEDISIWUIIO! existing C code. In June 1991, ICSI new code. For example, one might made the language publicly available write a visualization package that by anonymous FTP over the Internet displays data on a certain kind of (from."ftp.icsLberkeley.edu" in the display by making calls on display United States, "ftp.gmd.de" in Eu interface routines. At some later time, rope, "lynx.csis.dit.csiro.au" in Aus one wishes to have the package tralia, and "sra.co.jp" in Japan). The display its output on a new kind of release includes documentation, a display. Without an object-oriented compiler, a symbolic debugger, a approach there is no easy way to get GNU emacs programming environ the previously written visualization ment, and several hundred library routines to make calls to the new GRADEBOOK classes. Within a few weeks of the display interface. release, several hundred research Another example might be a Russell A. Stevens groups from around the world had system that makes use of a matrix to obtained copies. Since that time new hold information. One might later GRADEBOOK provides class development has become an decide to use a sparse representation teachers with a fast, convenient international cooperative effort. for the matrix, and want to avoid way to record student scores and having to rewrite all the code that Why Object-Oriented Computing? compute grades automatically. operates on the matrix. In each of Some of the options are plus-or- . The primary desired benefit from these examples one. might want the minus grading, weighting scores object-oriented languages is the abi code sometimes to operate on one in up to ten categories, handling lity to effectively reuse code. In type of display or matrix, and some incomplete grades, granting extra Sather, one writes a program as a times on the other. In fact, the actual collection of modules called kind of display or matrix may not be credit, dropping low scores, and "classes." Each class should encapsu known until the calls are made. issuing interim reports. late a well-defined abstraction. If We use the term "object-orient The program can combine classes these abstractions are chosen careful ed dispatch" to refer to this late when calculating distributions ly, they can be used in a variety of choice of which code to actually and display the result in histo situations. For example, the Sather execute. In Sather, each class defines library has a vector class that encap the structure of corresponding "ob grams. Scores can be organized sulates the common operations on jects." The class corresponding to an on summary sheets or as indi vectors (e.g., addition, dot product, object defines its "type." Objects are vidual records for students. tensor product, etc.). An obvious chunks of memory that are dynami Includes 58-page User's Manual. benefit is that less code needs to be cally allocated while the program is written for an application if it can use running, and which h~lVe a set of For the IBM PC classes that have already been writ· routines associated with them. These ten. An even more important benefit routines form the "interface" to the is that the resulting code is often object, and are defined in its corre $149.95 with a ten-copy site license better written, more reliable, and sponding class. For example, the class $39.95 for members of AlP Member easier to debug. This is because DISPLAY_l might have an interface Societies programmers are willing to put more defined by the routines draw_line care and thought into writing and and draw_circle. Any code that debugging code that will be used in performs actions on an object of this TO ORDER many projects. In a good object type must do so via these routines. Order using Visa, MC, AmEx, check, or oriented environment, programming We might later define a class DIS institutional PO. Specify 3.5" or 5.25" format. should feel like gluing together pre PLAY_2 that also defines the routines S/H $3.50 for first item ($7.50 foreign) and $.75 existing building blocks to perform draw_line and draw_circle, but for each additional item. for a different kind of display. A TASL new functions. In such a setting one Box 8202, NCSU • Raleigh, NC 27695-8202 can be confident that most bugs will variable disp can be declared to hold lie in the 10% or so of newly-written objects of either of these types. Call Toll-Free (800) 955-TASL (919) 515-7447/FAX (919) 515-2682 code, and not in the 90% of the code When a call like disp.draw made up by well-tested library _1 ine is made, the actual type of the Ask for details of AlP's SATISFACTION GUARANTEE Circle number 11 on Reader Service Card COMPUTERS IN PHYSICS, VOL. 6, NO.5, SEP/OCT 1992 445 object held in disp is checked, and descendant of VECTOR in the hierar many object-oriented language~, ob the appropriate choice of draw chy. Object-oriented dispatching is jects of these types have tags or tag _line code is chosen to execute. This only performed on the second kind of bits that specify their type. At run provides wonderful flexibility, be declaration. When the type is precise time, extra tag-checking code must cause one can cause new code to be ly specified, the compiler generates run in addition to any operations called by old code by defining a new direct calls, which are exactly as performed on the objects.