DEV Community

Mujeeb Ishaque
Mujeeb Ishaque

Posted on

Python Vs C++ (My Experience)

An Introduction

C++

Ladies and gentlemen, C++ is not a game, it's a powerful, typed, compiled language that powers everything from a random jet flying over your head to pretty much all the supercomputers of China.

Python

Python is an interpreted OO programming language and you get it pre-installed with approx. all the Linux distros. It can make websites, provide insights about the data, make predictions and those automated testing/hacking scripts that are available all over Github.

Python is not as most people boost it to be. It's certainly not the easiest programming language to learn. If you ask an experienced C++ programmer about his/her view, probably, they will say one thing for sure, "I hate indentation. Braces make the code look more organized." (not my view, I am a social person. I've asked this question to many fellows and got this response)

My Experience

C++

I got introduced to C++ while working with Data structures and algorithms and in the course "programming fundamentals". So, first things first, people/students really hate c++. They look like they are trying to survive the c++ course. In my experience, it's not that hard. it just takes time.

So the programs compile really fast and C++ itself is a really fast programming language. Back then, I wanted to crack the username and password of the website and I opted dictionary attack. The dictionary that I downloaded from the web was 200MB and the passwords were related to Europe and the US only. Let me explain, so the names of people in the US or UK are like. James, John, and the password might be "john123" or "james67858" respectively, but I am from Pakistan and names of people are more like Abdul, Muhammad. So that dictionary was futile, I had to make one for my region. I did make it, one in Python and another one in C++ just to re-learn c++ at that time because I had moved on to C#.

Python program was executed and after several seconds, I'd see the CWD populated with passwords.txt file with all the different combinations, etc.

Now here's the wonderful thing, I re-wrote the same code in C++ and executed it on the terminal and it finished. I mean, I executed it and it finished immediately. So, no wait? I checked the CWD for the file and it was there. I mean, it was so fast that I thought that maybe my code didn't produce a passwords.txt file but it did. damn fast!

C++ for GUI based applications isn't easy. All the programs that I wrote with C++ were purely terminal based and would probably expect an argument. I wanted to go advance so I started learning about multithreading and parallel processing and boy let me out. I didn't commit a crime please let me go to my family safe and sound. I ran away to Python.

Python

If you're doing things perfectly than nothing is easy. It stands correct for all fields of science and art. When you follow best practices and naming conventions, It sometimes takes several hours just to come up with a descriptive class and method names.

Multithreading and parallel processing are comparatively easy. Your productivity increases with python. You have an awesome package manager for python, you can share your required libraries/modules with one command i.e.

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

You can import libraries and hack the world sometimes with just 3 lines of code. I taught myself Django. Again, it's hard but takes less time(python increases productivity). For Example, normally, you would install server software and database and set up your project after several minutes but with python, it's just

django-admin startproject project_name
Enter fullscreen mode Exit fullscreen mode

that's it. You have a built-in server, built-in database, etc.

Browser automation is however relatively easy but it requires general programming experience. You literally have to install two packages i.e. selenium and beautifulsoap and you're on your way to scrap data and do things.

You can make a neural network in under 20 lines of code. You can create a network automation script using ssh modules and netmiko. You can create a GUI using either tkinter or PyQt5 etc. You can do lots of things with fewer lines of code.

Python is a great programming language that offers a lot of packages to make your life easier. The things that you want to do are probably already done by someone else somewhere and for some reason, there's also a library to do that specific task that offers a lot of abstraction and functionalities out of the box. It is wonderful to know that your workload has reduced exponentially just because there's a module already present that helps you achieve your goal.

Conclusion

I've had more enjoyment, more productivity and more help using python. I am not saying that C++ was hard, it just takes more time and brains which I lack. However, I still code in C++ because it's C++ and powerful/fast.

Lastly, python wins at certain tasks but c++ is certainly not behind. I've started to think that it's stupid to compare 2 languages with each other but this wasn't a comparison Afterall, it was just an experience.

Top comments (6)

Collapse
 
codemouse92 profile image
Jason C. McDonald

When you follow best practices and naming conventions, It sometimes takes several hours just to come up with a descriptive class and method names.

Not once you've been doing it for a long time. ;)

But then, "There are only two hard things in programming: cache invalidation and naming things."

Also, you should try out PyPy. It's always a couple of versions behind the latest Python, but it's JIT-compiled, so the speed is comparable to C++.

Collapse
 
mujeebishaque profile image
Mujeeb Ishaque • Edited

Thanks for the recommendation, Mr. Jason. Big fan here. I loved your series.

Collapse
 
dwd profile image
Dave Cridland

I thought the quote is "There are only two hard things in programming: cache invalidation, naming things, and off-by-one-errors"

Collapse
 
codemouse92 profile image
Jason C. McDonald

There are several versions. ;)

Incidentally, off-by-one errors don't tend to be that hard, at least not compared to the other two. I think the addition of that was a later pun.

Collapse
 
shivambachhety profile image
Shivam Bachhety

Nice article

Collapse
 
mujeebishaque profile image
Mujeeb Ishaque

Thank You!