C++ Programming/Programming Languages/Comparisons

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[edit] Language Comparisons

There isn't a perfect language. It all depends on the tools and the objective. The optimal language (in terms of run-time performance) is machine code but machine code (binary) is the least efficient programming language in terms of coder time. The complexity of writing large systems is enormous with high-level languages, and beyond human capabilities with machine code. In the next section C++ will be compared with other closely related languages like C, Java, C# and C++/CLI.

The quote above is shown to indicate that no programming language at present can translate directly concepts or ideas into useful code, there are solutions that will help. We will cover the use of Computer-aided software engineering (CASE) tools that will address part of this problem but its use does require planning and some degree of complexity.

The intention of these sections is not to promote one language above another; each has its applicability. Some are better in specific tasks, some are simpler to learn, others only provide a better level of control to the programmer. This all may depend also on the level of control the programmer has of a given language.

[edit] Garbage Collection

In C++ garbage collection is optional rather than required. In the Garbage Collection Section of this book we will cover this issue deeply.

[edit] Why doesn't C++ include a finally keyword?

As we will see in the Resource Acquisition Is Initialization (RAII) Section of the book, RAII can be used to provide a better solution for most issues. When finally is used to clean up, it has to be written by the clients of a class each time that class is used (for example, clients of a File class have to do I/O in a try/catch/finally block so that they can guarantee that the File is closed). With RAII, the destructor of the File class can make that guarantee. Now the cleanup code has to be coded only once — in the destructor of File; the users of the class don't need to do anything.

TODO

TODO
Split this explanation to RAII and only provide the reference

[edit] Mixing Languages

TODO

TODO
Add relevant information

By default, C++ compilers normally "mangle" the names of functions in order to facilitate function overloading, and generic functions. In some cases, you need to gain access to a function that wasn't created in a C++ compiler. For this to occur, you need to declare a function as external:

extern "C" void LibraryFunction();