Class-based object oriented CStroustrup Bell Labs. An object-oriented superset of C. In C++ a class is a user-defined type, syntactically a struct with member functions. Constructors and destructors are member functions called to create or destroy instances. A friend is a nonmember function that is allowed to access the private portion of a class. C++ allows implicit type conversion, function inlining, overloading of operators and function names, default function arguments, and pass by reference. It has streams for I/O. C++ release 2.0 - May 1989. Added multiple inheritance, type-safe linkage, pointers to members, abstract classes. "C++ 2.0 Draft Reference Manual" C++ release 2.1 Added nested types. "The Annotated C++ Reference Manual", M. Ellis et al, A-W 1990. C++ release 3.0 - Added templates. OOL. Derivative of C, "with classes".Inheritance, polymorphism, encapsulation, data hiding, reusability, etc, are all aspects of C++ and OOL. Very powerful and fast, but considered hard to learn. Developed by Bjarne Stroustrup, who desribes C++ as "a general-purpose programming language with a bias towards system programming that is better than C; supports data abstraction, OOP, and generic programming". He also said,"within C++, there is a smaller cleaner language struggling to get out". "Main problem with C/C++ is that the programmer is required to do their own memory management (to declare variables, explicitly manage pointer-chained lists, dimension buffers and detect or prevent buffer overruns, to allocate and deallocate dynamic storage" Eric S. Raymond. People: Structures: Related languages
References: in Bell Labs Journal. Vol 63, No. 8. October 1984 view details in Proc. IFIP WG2.4 Conference on System Implementation Languages: Experience & Assessment September 1984 view details in Proc. IFIP WG2.4 Conference on System Implementation Languages: Experience & Assessment September 1984 view details in Proc. Summer 1985 USENIX Conference. June 1985 view details in SIGPLAN Notices 21(10) October 1986 (OOPWORK Proceedings of the 1986 SIGPLAN workshop on Object-oriented programming Yorktown Heights, New York, United States) view details in IEEE Software 3(01) January 1986 (Multiparadigm language projects) view details in IEEE Software 3(01) January 1986 (Multiparadigm language projects) view details in Proc. EUUG Spring Conference, May 1987. view details in Proc. USENIX C++ conference, Santa Fe. November 1987 view details in European conference on object-oriented programming on ECOOP '87, October 1987, Paris, France view details in Proc. USENIX C++ conference, Santa Fe. November 1987 view details in USENIX Computer Systems, Vol.2 No. 1. 1989 view details in USENIX Computer Systems, Vol 1 No.4. Fall 1988 view details in SIGPLAN Notices 23(02) February 1988 view details in Computer Languages 14(3) view details Two of the hottest languages these days are Modula-2 and C++. They appeared in the early 1980s, and both are gaining in popularity. Each was designed and written by a single person: Niklaus Wirth created Modula-2, and C++ was developed by Bjarne Stroustrup. An additional similarity is that both languages are extended versions of earlier languages. This article contrasts Modula-2 and C++; it assumes you have a cursory familiarity with both Pascal and C (the root languages of Modula-2 and C++, respectively). Extract: Modula-2 Background Modula-2 Background Pascal was designed as a teaching language, to show students how to structure programs properly. It lacks intrinsic support for character strings, file I/O, and separately compiled modules. Pascal has many features that are useful in software development, and the language gradually gained popularity outside the academic community. Unfortunately, the vendors that implemented Pascal did not develop a standard for extending the language to cover its weak points. Thus, every Pascal compiler is unique, and porting programs between implementations is difficult. Wirth intended Modula-2 to be the successor to Pascal. Modula-2's name implies one of its basic concepts: modular program design. Through the use of modular facilities, Modula-2 supports data abstraction and encapsulation. All I/O is done through procedures in modules as an aid to portability. As long as the interface to the I/O procedures does not change, the implementation of those procedures can be modified for different environments without having to make alterations in the programs using them. Among high-level languages, only Modula-2 and Ada support multiprocessing. In addition, Modula-2 supports bit manipulation, generic types, and system-level access. Modula-2 (unlike Pascal) is well suited to the writing of system software such as operating systems and device drivers. Extract: C++ Background C++ Background C is a powerful system-level language; in its original definition, however, it lacked many features necessary for large, complex projects. Stroustrup designed C++ to amend problems with the C language, in much the same way as Wirth designed Modula-2 to correct the deficiencies of Pascal. C++ provides capabilities for strong type checking, modular programming, and data abstraction while maintaining full compatibility with existing C programs. Stroustrup borrowed the object-oriented paradigm from Smalltalk; classes and methods are the most significant additions he added to C in creating C++. In an object-oriented language, objects (data items) belong to classes (types), which have associated methods (functions). "Messages" are sent to objects via their class methods; the messages tell the objects how to act. For example, an object of class int would be given the message "add 1" by the ++ (increment) method. Although this concept can take some getting used to, it can be more appropriate than traditional program design methods. C++ is often implemented as a translator. The C++ translator works much like the standard C preprocessor, converting C++ programs into C programs. A C compiler is then run on the output of the translator, producing executable code. By its nature, this process is cumbersome and slow. Recently, manufacturers have released true C++ compilers. In addition to adding object-oriented capabilities to C, C++ offers other enhancements, including in-line functions, function prototyping (since added to the ANSI standard), and overloading. Because it retains all C's low-level facilities, C++ can be used for a wide variety of applications. Extract: General Language Features General Language Features Modula-2 and C++ have the following general features: * Source code format -- Source code is case sensitive in C++ and Modula-2. All C++'s keywords must be in lowercase; Modula-2 requires uppercase. * Data types -- Both languages are rich in data types and allow the creation of new types. They offer long and short, signed and unsigned, integers and reals. Strings in both languages are handled as arrays of characters terminated by a zero (NUL) byte. Both languages have pointer types. C++ provides the capability to smoothly integrate new types through its class structure, while Modula-2 provides generic types and better control over data item visibility. Modula-2 provides SET types (including BITSET, which allows access to the individual bits of an item), whereas C++ has C's bit structures. * Functions and procedures -- Modula-2 has procedures, whereas C++ has functions. The purpose is the same in both languages: to provide callable routines with parameters and local variables. Modula-2 allows the nesting of procedures within procedures, using the same scoping rules as it does for variables. Modula-2 and C++ parameters can be passed either by reference or by value. * Control structures -- Here, too, there are no important differences. Although the syntax may vary, the capability is the same. Both languages have loops with tests at both the top and the bottom of the loop. The for, which iterates through a succession of values, is available in both languages. There is (of course) the ubiquitous if ..else ..endif conditional construct. Useful multiple-condition branches (switch in C++ and CASE in Modula-2) are available. * Library routines -- C++ uses the standard C library, which is extensive and robust. Wirth defined several standard modules in his definition of Modula-2, but these provided only minimal capabilities. Most Modula-2 vendors have created expanded libraries for their implementations. Extract: Unique Features of Modula-2 Unique Features of Modula-2 Modula-2 is not a superset of Pascal; rather, it is an evolution of the earlier language. For example, one of Modula-2's most welcome enhancements over Pascal is its simplified block structure. A Modula-2 program is not filled with BEGIN...END pairs; each control structure has an implicit block terminated by an END statement. Where Pascal has functions and procedures (the former returns a value whereas the later does not), Modula-2 simply has procedures. A Modula-2 procedure returns a value if it is specified as doing so. One fascinating feature of Modula-2 is its support for coroutines, which are individual processes within a program that run concurrently. This allows multiple tasks (within a program) to be performed simultaneously. A word processor, for example, could use coroutines to allow a document to be printed while another is being edited. The strong type checking in Pascal prevents spurious errors but also causes difficulties. For instance, it is impossible to create a general function in standard Pascal that can accept arrays (such as character strings) of different sizes. Modula-2 introduces the concept of the open array parameter -- for example, a parameter to a procedure can be declared as an array without bounds (array of char). Any length array of the specified type (in this case, a character array) can be passed to that function. The procedure can then find out the actual length of the array with the built-in HIGH procedure. Modula-2 also provides the generic type. A WORD type is equal in size to the default word size of the hardware it is running on. In the case of MS-DOS, a WORD type is 16 bits long. Any type of the same size (usually the INTEGER and CARDINAL types) is assignment compatible with WORD. An extension of this is that any value can be passed to an open array of type WORD (that is, a procedure parameter of type ARRAY OF WORD). The size of the array is the number of WORD types required to hold the value being passed. The concept of modules allows Modula-2 programmers to control access to individually compiled portions of a program. The following object-oriented example illustrates how modules can be used. Extract: Unique Features of C++ Unique Features of C++ C++ refines and expands C while including all C's strengths. Several features of the emerging ANSI C standard are actually borrowed from C++. Examples of this are function prototypes, const, and void. Function prototypes were added so that C++ could do type checking or arguments; under the original K&R C, values of incorrect types could be passed to functions, often causing obscure errors. Const provides named constants. Adding void allowed the creation of generic pointers and made it possible to declare that a function does not return a value. Overloading functions lets the programmers create several functions with the same name but differentiated by their parameters. Instead of C's current crop of absolute value functions (abs, dabs, fabs, and labs), a C++ implementation could have the following: overload abs; int abs(int i); long abs(long l); float abs(float f); double abs(double d); At compile time, the C++ compiler determines which version of abs to use based on the parameters it is being passed. This facility can make programs easier to understand. It is possible to overload operators in C++. You can, for instance, create a new class that can use the same operators as existing classes. The section on object-oriented programming later in this article contains an example of operator overloading. The object-oriented features of C++ are prominent. Object-oriented programming requires a change in thinking for many programmers; instead of thinking in terms of the nuts and bolts of programming, programmers are required to visualize a program as a series of processes applied to data items. This may seem to be a subtle distinction, but it must be mastered to truly appreciate and use an object-oriented language. The object-oriented features of C++ are illustrated in the section on the subject in this article. C++ provides dozens of other extensions to C, including in-line functions, anonymous (unnamed) unions, and default function parameter values. There are dangers to the many features provided by C++. Whereas C has always been famous for providing the rope by which programmers hang their programs, C++ adds the noose. Care must be taken to avoid "going wild," especially with the overload capabilities. Extract: Conclusion Conclusion Modula-2 and C++ are powerful languages; both have bright futures. C++'s classes, methods, and overloading make it a powerful tool, but it has few restraints to keep programmers from being too "creative." Modula-2 is a strongly organized language with restraints to keep programmers within guidelines. It is not as extensible as C++, but it does implement its own unique features, such as SETs, coroutines, and open arrays. Which of these languages is more appropriate for a specific project will depend on the type of application and the experience of the programmers involved. Both languages are powerful and interesting to work with. in Computer Languages 14(3) view details in USENIX Computer Systems, Vol 2 No 4, Fall 1989 view details in The C++ Report. 1(1) January 1989 view details in The C++ Report. 1(1) January 1989 view details in SIGPLAN Notices 26(03) March 1991 view details in SIGPLAN Notices 26(03) March 1991 view details ![]() in SIGPLAN Notices 26(03) March 1991 view details in SIGPLAN Notices 26(03) March 1991 view details in SIGPLAN Notices 26(03) March 1991 view details in SIGPLAN Notices 26(03) March 1991 view details Resources
|