Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. C++ in Plain English (Publisher: IDG Books Worldwide, Inc.) Author(s): Brian Overland ISBN: 1558284729 Publication Date: 04/01/96 Search this book:
Previous | Table of Contents | Next
## PART I Core Features of C and C++ ## Chapter 1 Introduction: What C++ Will Do for You In the Dark Ages of computers, programmers were slaves to the machine. Developers had to write all their instructions in hexadecimal codes (representing 1's and 0's), the computer's native language. As time went on, newer programming languages gave programmers better ways to express algorithms. Improvements in computer languages meant that programmers could be less concerned with the internal structure of the computer and more focused on the purpose of the program. Object-oriented programming takes the evolution of software a little further. Although its benefits have perhaps been oversold, the object-oriented approach does improve programmer efficiency. In traditional, pre-object-oriented programming, the most significant structural element is the division between code and data. This division accurately reflects the internal workings of a computer, but it is not a realistic way of representing the world in general. Object-oriented programming, on the other hand, is analogous to the human brain. This organ is a colossal set of individual brain cells. To borrow computer terminology, each cell is an object, having both its own underlying material (data) and programmed behavior [code]. It would be nonsense to try to separate these different aspects of a brain cell, asking where its code is and where its data is. It would be greater nonsense still to ask where all the code of the brain is and where all its data is. This analogy summarizes what object orientation is all about: it replaces the traditional approach with an approach that makes objects the fundamental units. Objects combine state information and behavior, and each object is able to send and respond to stimuli just as cells in the brain do. Programs written with object-oriented languages don't automatically model reality better than other programs do. A successful program is more the result of careful thought, planning, and diligence than of the choice of language. Still, if you&$146;re going to adopt the object-oriented approach (and an increasing amount of system software requires it), there are features of an object-oriented language, such as C++, that are extremely convenient and helpful. Why C++? C++ probably isn’t the most widely used object-oriented language; more people probably use Visual Basic, and, arguably, Visual Basic is object-oriented. But C++ is a close contender. More significantly, C++ is viewed by most programmers as the most comprehensive object-oriented language. One can argue that Smalltalk or Eiffel is a more pure implementation of object orientation, but certainly C++ sets the standard by which other languages are measured. Knowing C++ has become important to a programmer's career, almost as important today as knowing C was a few years ago. (And thus the justification for this book!) Any large, serious development project started today is likely to be written in C++. To development managers, C++ is the wave of the future. In any case, it's worth asking: why use C++? As with C, the answer has a great deal to do with the need for both power and efficiency. ### The Origins of C++ C++ has its origins in, of all things, the Norwegian armed forces. From Norway came a language called Simula, one of the first languages to use classes (a class being a program unit containing both data and associated functions). Classes, as you'll learn in this book, are closely linked to the idea of objects, a class being an object type. Simula was developed to model events. Although the two concepts are not identical, an event-driven model of program organization is not very different from an object-oriented model. This is why Visual Basic, Windows, OS/2 Presentation Manager, and many other event-driven architectures are object-oriented or at least object-based. Object orientation is a natural way to implement an event-driven system, because it's based on the concept of independent objects that can respond to messages. Enter Bjarne Stroustrup, who in 1978 was writing a simulator for distributed computer systems as part of his Ph.D. at the Computing Laboratory at Cambridge University. Stroustrup found Simula's use of classes a perfect way of expressing the interaction of different machines on a network. The problem was that Simula was inefficient for the large-scale systems programming he was doing. He needed the object-oriented features of Simula combined with the power and efficiency of a language like… well, like C. C++ was born of this marriage. Stroustrup created C++ as a C language with classes and added Simula's stronger sense of data types. “C with classes” went through a few iterations before it became the C++ accepted as standard today. But the language is basically still a realization of Stroustrup's original vision of C married to Simula classes. ### Making the Transition from C to C++ You may have heard that C++ is a “better C than C.” What people mean by this is that C++ has a superset of the features found in C. They claim that you can compile the same program in C that you can in C++ and that, in addition, C++ provides some nice refinements you can add to your program without going all the way to object orientation. The first part of the preceding statement is only approximately true. Many C programs can be compiled as C++ programs without change, but an occasional nagging difference crops up in some programs. One of the goals of this book is to point out these differences as clearly as possible. The important point is that C++ does not impose object orientation on you. It may come as a relief to know that if you are a C programmer, you can switch to C++, observe the few additional restrictions that C++ imposes, and keep right on going. You don't have to rewrite anything as an object. As you spend more time with C++, you can gradually introduce more of the C++ extensions. ### Classes: Organization by Objects If you’re going to take the time and trouble to bother with C++ in the first place, though, you probably want to pierce to the heart of what C++ is all about: object orientation. Conceptually speaking, an object is simply a data structure that has built-in functions associated with it. (A class, which you'll read about a lot, is a type of object.) It may seem to you at first that C++ introduces quite a few new operators to deal with variations and special cases. Yet the idea of objects itself is elegant and simple.
Previous | Table of Contents | Next
[an error occurred while processing this directive]

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.