Hello folks, this is Punit Sharma from theoryofprogramming.com. Good morning, afternoon or evening accordingly, at whatever time you visit this article. So in this article, I will be providing you an essence of the C++ programming language and why you should use it or rather learn it.
First off, the name. You might be wondering what that “++” is doing there in the name. In many programming languages, ++ is an increment operator. So, C++ is meant to be the next version of C. Well, C++ language is always something that has been viewed as a cryptic programming language. It might sound as a huge understatement but many people are afraid to use or learn C++ just because of the fact that it is vast, and the concepts are too tough to cooperate with. So writing this article serves to be a clear intention to remove this rumor and helping you to use this language because it is beautiful, and will become more beautiful as soon as you get used to it. So let us define C++ in the words stated by its inventor –
“A light-weight abstraction programming language designed for building and using efficient and elegant abstractions and offering both hardware access and abstraction. Doing it efficiently is what distinguishes it from other languages…” – Sir Bjarne Stroustrup
So Stroustup’s intentions were pretty clear in the above statement. So how many of you agree to what was stated above?
The novice programmers or the ones who are acquainted with Java or C# as the only language in their life might find this statement least interesting. But trust me as well as Bjarne Stroustrup, this programming language brings to you object oriented programming in a taste which you never had with Java or C# when you learnt it for the first time.
How C++ is better?
Getting into insights of the language, the inbuilt sorting function of C++ uses Introsort which is a type of hybrid sorting algorithm (Hybrid of Quicksort and Heapsort) followed by an Insertion Sort on the result. In practical scenarios, in a coding competition, this sort function always serves as a better one than the sorting functions of other object-oriented languages. Let me show an illustration of this. Consider the problem given in the following CodeChef link – https://www.codechef.com/problems/DONUTS.
You can see the rankings with the image below –
This problem requires sorting of data at a certain point of the algorithm. And the top 15 submissions are either in C (26.77%) or C++ (73.33%). Moreover, the ones which are submitted in Java or any other language have a worse time and space factor. So C++ provides an extra edge from a competitive programming point of view as well.
Another performance factor where C++ serves as a better option than other OOP languages is in a scenario where objects are being created and destroyed in a loop running in order of 106 or greater than that. Although C++ needs manual allocation and deallocation of memory, it properly deallocates the memory at a good rate in the above situation whereas OOP languages like Java which boasts regarding automatic garbage collection have a garbage collector thread which performs very slowly.
Thus, memory allocations are being done at a faster rate and the rate of destruction being slower. Thus, any scenario like this will result in what we know as “Memory Limit Exceeded”….
Believe it or not, the giants in the gaming industry rely heavily upon C++. Video games still use C++. One example is the Torque engine which can be used for iPhone and Xbox game development. Another reason why this language is great – it is really cross-platform. It is used almost everywhere – PC, Mac, Xbox 360, PS3, cell phones, embedded… you name it. So you can use your skills on almost any platform you feel like. As opposed to many other languages, which are often only useful for one platform. So any aspirant of EA Sports, Nintendo, Sega, Ubisoft etc. should possess proficient skills in language and is a necessity while you submit a resume at this companies.
Not only that, advanced audio and image processing engines use C++. C++ is still used extensively for performance-intensive tasks. For example, a lot of work with video compression and decompression – it’s all C++. Partly because we need the performance, and partly because all the 3rd party libraries which need to use are C++. So it’s easier to integrate with them if we’re using the same language. C++ also leads to a good heat in your pocket or salary++ (the experts say) even if you work with a corporate powerhouse that does not work with the language. Bloomberg, Reuters, and all their bank/trading clients who want low latency market data feeds use C++.
Huff!!!!!! So enough of bragging done….! Hopefully, I was able to justify using the above facts that why C++ should exist and should be learnt and appreciated. There are other facts and features which you will definitely learn and understand in the upcoming articles and get lost in the beauty of C++. Some favourite quotes of mine by Sir Bjarne:-
- C++ is my favourite garbage collected language because it generates so little garbage.
- C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.