: A Pragmatic Comparison of Four Different Programming Languages

: Programming language debates are extremely common among programmers, computer science students and of course, software engineers. However, all of the above-mentioned professionals can concur that diﬀerent languages excel in diﬀerent scenarios. Software Engineers and programmers working on diﬀerent projects can easily use diﬀerent languages for diﬀerent tasks during their work. Every year diﬀerent programming languages are designed and created. In this Research, we will keep in focus the Four Horsemen of programming languages: C, C++, Python and Java; with respect to the criteria of time, speed and simplicity. The same optimized piece of pseudo-code is used to write the code of the diﬀerent programming languages mentioned above by following their respective syntax and rules. The results of the comparison will be displayed with the help of a table in order to simplify the ﬁnal results for the reader.


Introduction
"A Programming Language is like a natural, Human Language in that it favors certain metaphors, images and way of thinking" -Seymour Papert In 1950s, the first of the high-level programming languages were created and designed, with the purpose of shielding the programmer from the amount of effort it took to design even the simplest of programs in low level programming languages [2].
There are thousands of different programming languages that exist and different sources say different numbers. Wikipedia states that are around 700 different Programming Languages but HOPL states that there are 8,495, programming languages to date [3]. But, don't let this distract you from the fact that there are many new languages created each year all having different functionalities, capabilities and paradigms (Functional, object-oriented, reflective, aspect-oriented and imperative being the common ones).
There are some programming languages (e.g. Python, C, Java and C++) that are popular world wide and are used in almost every field because they are highly generalized and offer extreme control. However, language developers aim to create new languages whose purpose is to combine simplicity, power and efficiency and having support for multiple paradigms [2]. The main purpose of multi-paradigm languages is to facilitate the programmer so he can use different paradigms for different projects whichever is more efficient in any given scenario and realizing that any particular paradigm is not the best one.
There are so many languages out there but some of the languages are extremely popular like C, C++, Java and Python. So, Which language is better suited towards which task? Which language of these bunch is faster? Which offers more control and is easier to program in? In our research we will be performing two experiments and after that we will be able to draw a conclusion to answer these questions.

Similar Work:
In the Journal, "A Comparative Study of Language Support for Generic Programming" [4] detailed comparison of generic programming is carried on six languages: Standard ML, Haskell, Java, C++, C#, Eiffel but Python is absent in this research journal, which is now one of the most widely used language in the field of Artificial Intelligence and Data Science.
In the Journal, "Programming Languages: A Comparative Study" [2] authors have put plenty of effort and time to compare and contrast four languages: Lisp, C++, Perl and Java to assess their efficiency, complexity, re-usability familiarity, their IDE's. The authors also studied the number of lines, resources required and the memory consumption to implement the same program among these languages but once again Python is absent from this list.
In the Journal, "A Comparative Study between Computer Programming Languages for Developing Distributed Systems in Web Environment" [1] the authors studied and evaluated the performance of C++, Java and C# in the field of distributed systems in the web environment. In relation to the field, they also measured their simplicity, reliability, concurrency and maintainability of the languages. This work, however, also excludes Python from its list with its rich and easy to use web frameworks like Django and Flask.

C:
C is a successor to the programming language B. It was developed by the brilliant Dennis Ritchie at Bell Labs between 1972-1973. C gained popularity gradually and became popular enough to become the most widely used programming language. It provides an Imperative programming approach. It is a compiled programming language with low-level memory accessibility and functions like pointers. It was used to develop many low-level applications including operating systems such as Windows. It is a general-purpose programming language and it possesses great speed and efficiency when used by an expert programmer. It however, lacks Object Oriented programming.

C++:
C++ was designed and developed by Bjarne Stroustrup as an expansion to C. It was released in 1985, but in 1989 its newer version was released which added more advanced features while also adding error handling. It is a general-purpose programming language and is mostly similar to C with some key differences. It is a compiled programming language with a blend of both low and high-level features making it highly versatile. It supports full object-oriented programming, structures, unions, operator overloading and templates as well. It has full pointer support.

Python:
Python was developed and designed in 1991 by Guido Van Rossum. It is an interpreted programming language. It supports object-oriented programming. Programs written in Python are short and easier to understand and read because it is a highlevel programming language with minimal low-level functions. One major positive point of Python is that it has a huge library support making it highly efficient in almost all fields like Artificial Intelligence, Web Development and Data Science just to name a few. Since it's an interpreted programming language, it is slower as compared to C and C++, but it supports features like Garbage collection and Dynamic typing. Python is also extremely popular due to being beginner friendly.

Java:
James Gosling begin the work on Java in 1991 and after a steady development and design procedure released it in 1996. Java is an object-oriented simple and portable programming language developed at the Sun Microsystems lab. Its syntax is equitable to C++ with some major differences in the language itself. It is both a compiled and interpreted programming language with support for garbage collection. Some of the features missing are the absence of structures and unions both of which are present in C++, support for pointers is also limited in Java. One more major difference is that it is a "Write Once Run Anywhere" language because of JVM support.

Methodology:
Since Programming is all about speed and efficiency, our focus in the paper will be on the quantitative side of things with a little sprinkle of qualitative evaluations and conclusions as well.

Hello World in Four Languages:
In Python: In Java: In C: In C++: As it can be witnessed from the above programs: C, C++ and Java's hello world program has exactly 5 lines of code whereas Python's hello world program has a mere single line. This simple example can point us in one direction that C, C++ and Java's programs will become much longer the bigger the project is, whereas, Python's programs will be significantly shorter than the rest of the languages discussed here This experimental code will dynamically assign memory and initialize the array and perform lots of int and float calculations, its only purpose is to perform mass calculation and the algorithm's results are not useful for anything except for the purpose of measuring speed and efficiency. The experiment will be carried out on Windows 10 21H2 (Installed on SSD), with 8 GB of RAM running on Core i5 3rd gen 3570 with only essential background processes, so the results would not be interfered by anything else. This experiment will compare the efficiency and speed based on the criteria of: • Dynamic Memory Access (heap).
• Int and float calculations.
We ran the experiment exactly 5 times for each language and its program and then the average results are calculated and displayed in the above table. The experiment presents us with some interesting information, like Python had two more lines of code then Java, which made it the 2ND in our experiment on the number of lines and surprisingly Java had the least number of lines with C and C++ having an equal number of lines as expected.
C had the least CPU usage with C++ only falling behind it by about 8%. Python had the most CPU usage as expected because it's interpreted whenever the code is running. Java on the other hand had about 2 percent less CPU usage then python.
The execution time presented us with a big disappointment from Python as it took a whopping 2900 MS (or 2.9 seconds) to perform the calculations, showing us that if speed is a factor (which is a huge factor) then you are better of to picking something else like C which had the least execution time with C++ on the 2ND place with only a negligible difference and once again Java sitting comfortably in the middle with about 69 MS more execution time then C which is still quite less as compared to Python.
From the experiment we can conclude that, if speed is of importance then C, C++ or Java should be chosen, however, if speed is not of importance and rather the handling and less complexity of code is the priority, then Python can be favored instead.
For experiment 2, we choose to do large matrix calculations. The size of the matrices was kept 1024 x 1024 and random values were assigned to them from 0.0 -1.0 (the effect of random values has no effect on the results). The experiment was conducted 5 times for each language and the average was calculated. When the results for the languages were out, we were confused at first because Java's program ran faster than C and C++, but then we realized that Java and Python's compiler by default performs optimizations, keeping this in mind, we turned towards our C/C++ compiler and used the "-o3" optimization flag, and the results were quite shocking, the optimization flag not only gave the lead to C and C++, but it also widened the result's gap by a large margin as seen from the Table: The result presented us with some interesting information, Python took most time and we had to sit and wonder what was happening around us, but the rest of the languages were quite competitive with each other, but however, C++ with its optimizations flags, took the victory by a huge margin from Java but C as it's predecessor remined close with negligible difference only.
The amount of difference -O3 made was quite surprising and was rather unexpected, we hoped it would shove off 5 or 6 seconds, but to our surprise it rather rounded of 15 seconds which is huge in the world of computing where even milliseconds of efficiency counts.
From the above experiments, we can conclude that, if the goal is speed efficiency and reliability then C++ is the king of all the languages we compared, it takes the lead from C because it offers wider support of approaches because of supporting OOP which is absent in C. When developing system software like Drivers and Operating Systems, C still holds strong as compared to C++.
Java is the middle ground of all languages, if you can't agree on the complexity of C but also want the speed that Python lacks then Java is your best bet because not only it offers "Write Once Run Anywhere" support it also automatically applies optimizations, something that a beginner programmer might not be familiar with.
Python is best used if you want to write software where speed is not of major concern. It is also a great choice for beginners and for fields like Data Science and Artificial Intelligence because of the huge number of libraries it offers.

Future Work:
In the future, we will perform more experiments on these languages as well as including newer languages. Since the field of computer science is continuously evolving, we have to evolve with it as well because it is the future of everything from medical to engineering, there is absolutely no field that cannot benefit from computing but some fields require higher accuracy and precision from the rest because many lives depend on them, like offering faster and less radiation induced X-Rays. There is nothing that won't benefit from efficiency but for that we have to continuously design and write better and efficient code for our machines.

Acknowledgement:
We would like to offer thanks and respect to these persons or entities, without whom this research might not have been possible or would have been difficult.
• Our Parents for their continued support.
• Xara, for giving us tools to create the beautiful tables we used in this research.
• Gregory, for the Source codes used in Experiment No. 1.
• Gunavaran, for the Source codes used in Experiment No. 2.