By: De Jesus, Antonio L.
January 09, 2012
C++ has taken a lot of criticism: it's a big language that takes a long time to learn; standardization has taken a long time, which has made it hard to write portable code; newer languages, notably Java, draw more media attention. Still, among languages that support an object-oriented style, C++ is by far the most heavily used, and its usage is still growing rapidly. Why? Some of the complexity of C++ is inherited from C, or results from its evolutionary history, but most is a consequence of the language's power. For an easy problem, any language will do; a hard problem demands a powerful language. Each feature of C++ exists because it has proven important for some area of industrial programming. With the language standard nearly complete, compilers that implement most of the new standard features are available now on most architecture. Real-world programmers are more interested in problems than in languages: a programming language is a way to solve a problem. When you use the right mix of languages and language features, the solution to a problem is much easier to describe and implement, with better results. C++ remains an essential tool for software engineers not because anybody thinks it's the best possible language, but because it's a single, portable language that works better than any alternative in each of several areas. This article explores the strengths of C++, and how to exploit them in your projects. * Why Use C++?
C++ is a general purpose programming language designed to make programming more enjoyable for the serious programmer. For many uses, C++ is not the ideal language. You might prefer Tcl/Tk for writing a user interface, SQL for relational database queries, Java for network programming, or Yacc for writing a parser. C++ is used because it works well when the ideal language is (for whatever reason) not available, and because it interfaces easily with the libraries and the other languages you use. It's no accident that you can interface C++ with almost any language interpreter or library you find. You rarely find a big program written all in one language, or without using libraries, so easy integration with other languages and libraries was a key design goal. Most problems have no specialized language to solve them; some because none has (yet) been worth creating, and others because an interpreter would add too much overhead. When you can't afford a specialized language for part of a problem, a library may suffice. C++ was designed with libraries always in mind, and its most useful features are those that help you write portable, efficient, easy-to-use libraries. Reference: www.cantrip.org
Why use C++ instead of Java?
Java needs to be interpreted or JIT compiled, while C++ is compiled directly into machine code. At compile time the compiler with knowledge of the CPU can heavily optimize the code which is not possible in a JIT that has much stricter run time requirements. It depends on what you compare.
There are shootouts that compare C++ code compiled for a 386 with 387 FPU with Suns Hot Spot engine on a current CPU. Since the java engine knows the CPU that it is running on, it can optimize for the MMX and SSE units and the more subtle issues of that specific CPU. Those shootouts are usually used to prove that java was faster than C++. If your compiler optimizes your C++ code for the CPU it will be running on, the compiler still can do more sophisticated optimizations that a Java JIT never will be able to do in the short time it has for compilation. There are also some things in the languages. Java is a more dynamic language than C++. A C++ compiler can e.g. do heavy in lining of non-virtual methods. In java all methods are what a C++ virtual method would be. Templates are completely interpreted at compile time, where generics are more or less a feature for mass...