History of Computers - C++

From SJS Wiki
Jump to: navigation, search

The C++ programming language is based on C; the "++" refers to the incrementor operation (i.e. the name essentially means "an improved version of C"). The main improvements include generic and object-oriented programming. C++ was designed by Bjarne Stroustrup (bjɑːnə ˈsdʁʌʊ̯ˀsdʁɔb[1], be-AR-nay STROV-stroop[2]) in 1983 while he worked at AT&T Labs.[3]

Overview

Generic Programming

In C, to define a function that, for example, adds the squares of two numbers, one would have to define a new version for each type of number:

int sumsq_int (int x, int y) {
  return x*x + y*y;
}

This would have to be repeated a number of times, substituting a different primitive type for int. C++, however, includes support for generic programming, and the code can be shortened to the following:

T <T> sumsq (T x, T y) {
  return x*x + y*y;
}

This greatly speeds coding time and allows for easier bugfixing. As an algorithm gets more difficult, it becomes much more difficult to correct an error in every version of it. Another benefit is that this function can be used with any user-defined type that supports operator overloading of multiplication and addition.[4]

Object-Oriented Programming

Perhaps the largest difference between C++ and C is object-oriented programming (OOP). C contains an object-like construct, known as the struct. However, a struct cannot contain functions and all of its internal variables, or members are exposed. In a class, this is often undesirable. C++'s classes can also be parameterized, in accordance with its generic functions.[4] Object Oriented Programming is favorable because the code is easily reused in other programs, it forces the designers to plan extensively, and it is easier to modify.

Function Overloading

The C programming language does not allow any two functions to have the same name, even if they accept different datatypes as arguments. However, in C++ functions with different signatures can have the same name.[4]

Operator Overloading

In C++, classes allow the programmer to make their own datatypes, removing many restrictions of purely procedural programming paradigms. An extension of classes and function overloading is operator overloading, which allows the programmer to overload the built-in operators, such as multiplication and addition, for their own classes by naming the function operator* or operator+.[4]

Significance

C++ has influenced many other programming languages, including Java and C♯. Java is an extremely popular language, used primarily for servers, but also used for cross-platform applications. C++ is also used extensively in games development, as evidenced by two of the most popular game engines, Valve's Source Engine and Epic Games's Unreal Engine. C++ is ideal for this type of development because it requires the speed provided by a low-level language with the abstraction provided by object orientation. In addition, the popular browsers Firefox and Chrome are both written in C++.

References

  1. http://en.wikipedia.org/wiki/Bjarne_Stroustrup
  2. http://www2.research.att.com/~bs/bs_faq.html#pronounce
  3. http://en.wikipedia.org/wiki/C%2B%2B
  4. 4.0 4.1 4.2 4.3 http://www.learncpp.com/