History of C++
C++ is merely an improved version of the C programming language. There are obvious differences between C and C++, however, in essence they are really quite similar. C++ was first developed in the 1980’s at the AT&T Bell Labs, where the Unix operating system was created.
Now if you actually want to learn C, this is not the place. As mentioned above, C++ and C are not completely different but it is sometimes nice to learn the original first. It is advisable to read a book about driving and rules of the road before learning to drive, however, it is possible to learn to drive without first reading any manuals. Of course it would first be necessary to learn the rules of the road before driving on a public road -- but this would not prevent you from being taught the basics on an open parking lot.
The developers of C++ had many issues to consider. When C++ was being developed, the writers of C++ had many issues in mind. One of these issues was actually local to the compiler, the file extension schemes. The two most popular compilers Microsoft and Borland use *.cpp for source files and .h for header files. There are other companies that use *.cc for source files and others who use completely different extensions. In this lesson we will be using *.cpp and *.h. The code will be compatible with both Microsoft VC++ 5.0+ and Borland C++ Builder 3.5+.
There are three main goals of programming, which are very important for all programmers to know. They are
- Correctness,
- Efficiency, and
- Maintainability.
Each of these three goals is very important in it’s own unique way. But it is also important for you as a programmer to understand that not all three goals can be met at any given time...that is why it is very important to consider the tradeoffs between each goal.
Correctness not only means that your program has to be correct in terms of syntax, but also in terms of the logic and the unsuspected. Logic wise and syntax wise, you need to make sure that your program does all things right.
Correctness also applies to the use of standard coding schemes rather than bizarre and out of the box ideas that seem to just make things a bit harder to follow. Imagine it this way: you are the programmer of a small IT Firm, the only programmer. You make the programs everyone uses and you do it your way. One day you move on, and the company has to hire a new programmer to finish a project that took you almost 5 years, as you can already guess the new programmer has absolutely no idea where to start and what to expect next. Thus all of your time and money spent into that project go to waste, because it will cost much more to debug and complete that project than it would to just start from scratch. Now apply the same scenario to a bigger company, you see correctness is key to maintaining such a large project. This brings us to the next goal, efficiency.
Efficiency not only means that the program or language construct has to be efficient time wise, but also size wise. An efficient program is one that is fast and lightweight. Just like correctness, efficiency is very important to programming. In fact, it is the sole reason why many programmers chose c++ over many of the other languages.
And the last but not least, maintainability refers to having portable and multi-platform code, and also code that is well written and well commented. Commenting in C++ is one of the new (and improved) features in C++ from C. In the old C, comments were a hassle; single line comments were introduced in C++ and to this date have been a great advantage in producing maintainable code. Thus it is always best to make your code as readable as can be. For instance, a programming teacher once told me that if my code is unreadable by a third grade student, then it needs to be commented more or cleaned out a bit.
In order to deeply understand the effects of considering programming goals in coding, observe the following code constructs:
 | |  | | |
// two ways of accomplishing the same task:
// strcat I
// the normal routine
char * strcat(char * dest, const char * src)
{
int i, j;
// first find the strlen of dest
for( i = 0; dest[ i ] != ‘
|
|
|