DEV Community

Cover image for Python is Slowly Losing Its Charm
Jason Dsouza
Jason Dsouza

Posted on • Originally published at towardsdatascience.com

Python is Slowly Losing Its Charm

The Swiss Army Knife of Programming Languages has its problems and may be replaced by other languages better suited for the task

Ever since Python was released in the early 1990s, it has generated a lot of hype. Sure, it took the programming community at least 2 decades to appreciate its existence, but since then, it has far surpassed C, C#, Java and even Javascript in popularity.

Although Python dominates the fields of Data Science and Machine Learning, and, to some extent, Scientific and Mathematical computing, it does have its share of disadvantages when compared to newer languages like Julia, Swift and Java.

What made Python so popular?

One of the main driving points behind Python's meteoric growth was how easy it was to learn and how powerful it was to use, making it extremely appealing to beginners and even those who shied away from programming because of the hard, unfamiliar syntax of languages like C/C++.

The language, at its very core, emphasised extensively on code readability. With its concise and expressive syntax, it allowed developers to express ideas and concepts without writing tons of lines code (as would be the case in lower-level languages like C or Java). Its simplicity a given, Python seamlessly integrates with other programming languages (like offloading CPU-intensive tasks to C/C++), making it an added bonus to polyglot developers.

Yet another reason for Python's versatility is its heavy usage by enterprises (FAANG included) as well as countless smaller ventures. Today, you'll find a Python package for pretty much anything you can think of - for scientific computing, you've got Numpy, Sklearn for Machine Learning and Caer for Computer Vision.

Python's Got Weaknesses

It's slow, terribly slow

turtle

This is probably a no-brainer. Speed is generally considered to be one of the key focuses of a developer and will probably continue to be for an unforeseeable amount of time.

Among the major reasons why Python is "slow", it really boils down to 2 - Python is interpreted as opposed to compiled, ultimately leading to slower execution times; and the fact that it is dynamically typed (data types of variables are automatically inferred by Python during execution).

In truth, this argument that "Python is slow" tends to factor a lot among beginners. Yes, it's true. But only partially.
Take, for example, TensorFlow, a Machine Learning library available in Python. These libraries were actually written in C++ and made available in Python, sort of forming a Python "wrapper" around the C++ implementation. The same goes for Numpy and, to an extent, even Caer.

It's got a GIL(l)

One of the major reasons for Python's slowness is the presence of GIL (Global Interpreter Lock) which allows only one thread to execute at a time. While this boosts the performance of single threading, it places a limitation on parallelism where developers have to implement multiprocessing programs as opposed to multi-threaded ones, to improve speeds.

Not the best for memory-intensive tasks

When objects go out of scope, Python has automatic garbage collections. It aims to remove a lot of the complexities involved in memory management that C and C++ involve. Owing to the flexibility (or lack thereof) of specifying data types, the amount of memory Python consumes can quickly explode.

Moreover, some bugs that may go unnoticed by Python may pop up during runtimes, ultimately slowing down the development process by a considerable factor.

Weak Presence in Mobile Computing

mobile

With a large shift from desktops to smartphones, it's obvious that more robust languages are required to build software for mobiles. While Python has a sizable representation in desktop and server platforms, it tends to lose out on mobile development owing to the lack of strong mobile computing processing.

Over the recent years, there has been a lot of advancements in this area, but these newly added libraries aren't even close to their strong competitors like Kotlin, Swift and Java.

The Rise of Other Languages

Recently, newer languages like Julia, Rust and Swift have popped up on the radar, borrowing a lot of the good design concepts from Python, C/C++ and Java - Rust pretty much guarantees memory safety and concurrency at runtimes, and offers first-class interoperability with WebAssembly; Swift is almost as fast as C due to its support for the LLVM Compiler Toolchain, and Julia offers asynchronous I/O for I/O intensive tasks and is blazingly fast.


Conclusion

Python was never built to be the best programming language. It was never built to take on C/C++ and Java. It was built to be a general-purpose programming language that emphasised on human-readable, English-centered syntax that allowed for the quick development of programs and applications.
Python, like every other language at the end of the day, is a tool. Sometimes, it is the best tool. Sometimes it's not. Most often, it's "just okay".

So, is Python as a programming language, dying?
I hardly think so.

Is it losing its charm?
Ah, maybe just a bit. Just a bit.

Top comments (5)

Collapse
 
king11 profile image
Lakshya Singh • Edited

So you clearly disregarded the point that there are two things when deciding how fast is a language. One thing is how much less code you are writing in python which is very less due to abundance of libraries and easy installation with dependency manager like pip. So the factor of writing slow runtime code is clearly covered up by less code written eventually allowing you to get your software into the public quickly.

Collapse
 
cipharius profile image
Valts Liepiņš

Right, I think this is the main appeal of Python and the reason why it gets commonly used for scientific calculation.

Often for research, one needs to create code that will be used for a limited period of time, having only one user - the researcher itself. So this is an ideal use case for Python, since one does not want to spend a lot of time writing code that will get thrown out eventually.

Collapse
 
kcubeterm profile image
Krishna Kanhaiya

and what about user perspective.

Collapse
 
king11 profile image
Lakshya Singh

The other is stated above python being a interpreter based takes time to run but that is actually a benefit because you can pin point the issue is at which line

Collapse
 
doubledare704 profile image
Oleksiy

At first version, python was designed for scientific usage, so people didn't have to learn c++ or c and write more code for PoC scripts\programs. Nowadays, python is popular due to web frameworks and ML engines, science libs. As for ML and science libs, they use C calls, so it speed ups whole program, but it's not plain python language. As for GIL, you can avoid this, if you will write C calls for your script, but now you are controlling memory and deadlocks on your own. GIL was added to language to avoid problems with threads, write\read same memory structure.

As for me, I think, that in ML and web world Python became cooler, also after 3.5-3.6 release. This language has own niche and for now Python is not going to leave it.