Why should I learn C++?

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 –

C++ in Competitive Programmingcodechef_rank2

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.

2 thoughts on “Why should I learn C++?

  1. There are always 2 sides of a coin. You have not mentioned the other side. The other side is described in this article (http://harmful.cat-v.org/software/c++/linus). And have you ever wondered why is the best solution always in C. Further more, competitive coding requires absolutely no OOP principles. C++ is though very good for video games and stuff. C++ comes with many over heads not as much as Java but more than C.

    • Ya it definitely comes with lots of more overheads than C. Because as the facilities and features grow. You should also be ready to face the overheads. That is something which comes as a spontaneous part. Also I agree to your point that it has a darker side too….. 😛 . Those darker sides will be discussed on as I proceed along with further articles. Its just an introduction and to make the guys at ease with the language . Regarding the darker side which have been discussed in the link provided by you . STL and boost is something which is not at all painful. Its just the perspective of the programmers which makes it either good or bad. Many people are under the impression that the language they have learnt is the best language and no one has the ability to defeat this language. Every language has its own glory and features and one should try to learn it rather than complaining about it- Be it complex or simple. On the Codeblocks 13.12 platform I work on, the C and C++ compilers both generate platform specific object code and use exactly the same back end optimizer. I’m hard pressed to think of any code strutures that would generate different object code, so the argument of which is faster is absolute non sense . To me, the real question is which is more productive to write in and that is C++, hands down. And regarding the competitive coding part which you said I mentioned only one point regarding the inbuilt library function that is std::sort() and nothing was said about OOP in grounds of competitive coding.
      As said by an expert and observed by me as well :-
      You pick C when
      1.)you need portable assembler (which is what C is, really) for whatever reason,
      2.)your platform doesn’t provide C++ (a C compiler is much easier to implement),
      3.)you need to interact with other languages that can only interact with C (usually the lowest common denominator on any platform) and your code consists of little more than the interface, not making it worth to lay a C interface over C++ code,
      4.)you hack in an Open Source project (many of which, for various reasons, stick to C),
      5.)you don’t know C++.

Leave a Reply