What was C++ introduced for? Drawbacks in languages such as C, Simula, ALGOL, BPCL made Bjarne Stroustrup , a Danish computer scientist begin his work on C++ in around 1979, the era when these languages already existed and had varied uses. The idea was to use C as a base and inculcate features of Simula (An OOP language), that would promote features such as code reusability, general level abstraction etc. Why the name C++? According to Stroustrup, the ‘++’ (post increment operator) in C++ symbolizes the evolutionary changes made from C.
Bjarne Stroustrup, the brilliant creator of C++ .
Why C in C++?
C was used as a base as it was reasonably popular at that time and also was fast, portable and easy to understand. Overall, in C++, using a general purpose language we could now do general level abstraction (Simula) and at the same time stay close to the hardware, which made it easy to perform highly demanding computer tasks with great speed and ease.
All right, enough of 1980’s. The important question is, with the advent of languages such as Java, is C++ still needed? The fact that C++ is still very popular should answer that question. Why? Read on we’ll cover that later in the article.
The killer feature (RAII)
C++ is the only widely used language in the industry which supports the feature of RAII. For those, who aren’t familiar with what RAII is, it basically stands for Scope Bound Resource Management. The control C++ provides over the lifetime of the objects it generates is something that garbage collection or any other management method lacks. In fact, in other languages, a common problem encountered is that objects exist beyond their lifetime. In C++ the objects can be acquired as well as be released in a deterministic manner.
What about performance?
C++ performs better than all recently made languages such as Python or Java, which despite having large libraries are no match for C++. The reasons for this unbeatable performance are brevity, modular programming and, of course, closeness to the hardware.
Brevity? Modular programming?
Brevity: Brevity refers to compactness of code. In other words, how short is the code, measured as LOC (Lines of Code). The more lines of code the more a project costs and performance takes a hit as well. This is why many companies such as Adobe, Amazon, Apple, Facebook, Quora etc., all have some parts of their basic codes written in C++.
Modular Programming: One of the most important aspects of Software Engineering is the concept of Modularity, which besically means the ability to build different, independent modules and later link them together in a program during compilation or run time. C++ not only promotes modularity within itself, but also with other languages, such as Assembler or C.
Hello world
#include<iostream>
Using namespace std;
Int main()
{cout<<”HELLO WORLD”;}
That sums up the Hello World program. As you can see the simplicity in the write-ability of the program is similar to C. In fact, in this program the only change is the use of cout operator instead of printf() function.
STL: The Cool Library
In the previous tutorial about C, we discussed the insertion sort program in C. You can do the same in C++, using the same logic, but insertion sort is rarely used and some of the sort functions are difficult to write every time. Apart from sort(), the programming of ADT (Abstract Data Types) , functions for linked lists, queues,stack etc. can make programming a really cumbersome job. This led to the introduction of STL (Standard Template Library). STL not only helps you program, but also introduces brevity along with a reduction in compilation errors.
If you want some additional details on what STL is, refer to its wiki page
Remember the question we asked before, about whether it’s still relevant? We’ll answer that now:
First of all let us consider the popular Operating Systems today. Windows, Apple OS, Symbian OS are all developed in C++. In fact popular Windows editions such as Windows 95, 98 and XP have been written prominently in C++. C#, a language developed by Microsoft for it’s DotNet framework is significantly based on C++. In fact, knowing C++ makes it very easy to learn C#. Apart from the use in OSes, popular Internet browsers such as Firefox and email clients such as Thunderbird are made using C++.
Both Linux and Mac OS-X use C++
Here is a list of game engines – 80% to 90% have been built on C++. Advanced multiplayer gaming, 3D gaming and management of resources are some of the features which make C++ imperative. The infamous ROOT framework created for the high energy physics problems by CERN uses C++. Plus, here are some software you probably have used: Adobe Systems use C++ for various applications such as Adobe Premier, Photoshop, Illustrator, InDesign, etc. Google Chromium and File systems have been reportedly been using C++ too. Even in the field of Database Design, MySql which is probably the world’s most popular database software, has parts written in C++. CAD systems in Civil Engineering by companies such as 12D have been programmed in C++. Head here for a longer list of stuff that’s made using C++, and it’s a trustworthy source as it’s a page written by the creator of C++ himself, Bjarne Stroustrup.
Tools and learning resources:
The best part about C++ is the programming environments available for it. There are numerous IDE’s available, depending on the OS you use:
Windows: Codeblocks, Microsoft Visual Studio, EMacs, QtCreator, DevC++ and many others.
Linux: DevC++ or NetBeans.
Mac OS: Xcode and Eclipse along with CDT will do. Emacs, VIM and QtCreator can also be used on any of these OSes. From the IDE’s listed above, Microsoft Visual Studio and QtCreator are suggested for the development of projects because of the tools and resources they provide. Also, QtCreator is available for free, so there’s that. Another cool resource is www.ideone.com which is something you can use to complile code online. Just for the knowledge of the reader, the compilers used in C++ are GCC(*nix) & MinGw, the windows port of GCC. Thanks to the popularity of C++ and the immense amount of online resources, videos, project repositories available, learning C++ these days is no big deal for anyone who knows how to use Google. We recommend sites such as redhoop.com or Noexcuselist for that matter to go through the MOOC’s available.
QT Creator
Several sites and even YouTube channels offer C++ tutorials. Then there is the vast library of good books to choose from:
A complete list of books can be found here.
Apart from all these, check out this article and this as well, which detail the special features of more recent updates to C++.
Once you get started, we suggest working on projects. Here are a few:
This article has about 150 different projects that can be built in C++ ranging from Networking to numbers to even stylizing HTML documents.
This is what a good text editor looks like
Specific projects we recommend?
Build your own Text editor:
You don’t have to build something as good as the picture above, but attempting to will show you the ins and outs of the language – by coding for functionality such as open, view, edit, save file and so on. Take a look here which we feel is a good article for this project.
To give you an idea of the usage of C++ libraries in the Industries here’s a link to a github repository. This will take you to development of library named Folly, which is now being used and developed by Facebook. Folly aims at increasing performance of the system overall. Another example of C++ enhancing performance of the system.
Interested ones may try reading this too. Another tool developed in C++ and used by Facebook.
Codeblocks{Can be grouped under the name C++ IDE’s}
For tutorials on 15 other hot programming languages go here.