The Good and the Bad of Python Programming Language
Have you ever wondered why Python is called “Python”? Spoiler alert – it has nothing to do with the snake. The story goes as follows: When Guido van Rossum (the father of Python) began implementing the language, he was reading the published script of a BBC comedy series from the 70s called Monty Python’s Flying Circus. As you must have guessed already, it is from this show that he got the inspiration for the name.
If you want to know more about Python, read on. In this article, you will learn about its history, pros and cons, where it is applied, how it fares against other popular languages, and how you can start learning it.
What is Python?
Python is a general-purpose, interpreted, object-oriented, high-level programming language with dynamic semantics. But what do these terms mean? Let’s break them down individually.
General-purpose. Python is not associated with a particular industry or domain. It covers a wide range of tasks and is commonly used across numerous fields, including
- web development,
- data analysis,
- machine learning,
- DevOps and system administration,
- software prototyping, and
- many others.
How Python is used. Source: Python Developers Survey 2020 Results.
This distinguishes Python from domain-specific languages like HTML and CSS limited to web design or SQL created for accessing data in relational database management systems.
Interpreted. In Python, the source code is compiled into the intermediate format called bytecode. This compact, low-level language runs on a Python virtual machine (PVM), which is software that mimics the work of the real hardware. The PVM, in turn, acts as an interpreter: It translates bytecode instructions one by one into machine code, directly at runtime.
While Python has a compiling step, it’s not the same as in compiled languages like C++ or Swift work. The latter compiles directly into the machine code in one piece, before execution, with no intermediate step.
Compiled vs. Interpreted programming languages
Object-oriented. Similar to Java, Ruby, C++, and many other popular programming languages, Python supports object-oriented programming (OOP) that concentrates on entities or objects developers will work with. An object represents a real-life thing or abstract unit, with its unique properties (state) and behavior (methods.)
Often seen as a pure OOP language, Python, however, allows for functional programming, which focuses on what needs to be done (functions.) In large codebases, there can be switches between two paradigms, depending on the specific goal.
High-level. Python belongs to high-level programming languages that resemble natural language and is not tied to a particular computer’s processor. By contrast, a low-level language offers little to no human-readable elements, as it sits close to hardware and is often optimized for a specific CPU (central processing unit.)
Dynamic semantics. Python uses dynamic typing, which means developers don’t have to declare a variable’s type. It will be automatically recognized at runtime based on the value assigned to the variable in question. The same variable can change its type many times during program execution, which is impossible with statically-typed languages.
Now that we know what Python is, let’s take a brief look at its history.
A brief history of the Python programming language
2021 Stack Overflow survey of the most popular technologies.
The story of Python begins in the late 80s with the programming language ABC. It was created in Amsterdam at the Centrum Wiskunde & Informatica (CWI) to enable people without sufficient experience to start coding for computers pretty quickly. Unfortunately, ABC didn’t work as expected. Later, one of its developers, Guido van Rossum used the failed language to build Python.
“I decided to try to design a simple scripting language that possessed some of ABC’s better properties but without its problems,“ related Guido in one of his interviews. “So I started typing. I created a simple virtual machine, a simple parser, and a simple runtime. I made my own version of the various ABC parts I liked. I created a basic syntax, used indentation for statement grouping instead of curly braces or begin-end blocks, and developed a small number of powerful data types: a hash table (or dictionary, as we call it), a list, strings, and numbers.”
The official Python’s date of birth is February 20th, 1991, when Guido published the first version 0.9.0. It came with all key data types, functions, support for OOP, and module system.
In January 1994, Python version 1.0 was launched with tools for functional programming (lambda, map, filter, and reduce).
In October 2000, Python version 2.0 introduced important improvements such as a support for Unicode and a garbage collector for memory management. The feature automatically releases memory that is no longer in use, making it available for other purposes.
Eventually, December 2008 saw the introduction of Python version 3.0, which was not an update but rather a completely new project, incompatible with 2.x releases. Due to the different bytecode and virtual machine, you couldn’t run Python 2 on the Python 3 VM and vice versa. The fresh release also got rid of many obsolete features and structures accumulated over the years of the language’s existence. But it was not until April 2020 when Python 2 lost support and officially retired.
Coming back to Guido, he was a Lead Developer of the project till July 2018, when he announced his permanent vacation from his responsibilities as Python’s “Benevolent dictator for life.” A couple of years later, he joined the Developer Division at Microsoft. “It’ll make using of Python better for sure (and not just on Windows),” promised the Dutch programmer in his tweet.
Python author’s tweet from November 12th, 2020.
Meanwhile, Python is ruled by a 5-member council, elected after Guido’s retirement by the Python community. Together with millions of developers worldwide, they continue working on the language, enhancing its pros and purging its cons.
Pros of Python
We briefly mentioned some Python advantages when describing its main characteristics and what Python basically is. Now, let’s heap on more detailed praise.
Smooth learning curve
Python is extremely beginner-friendly and relatively easy to learn. No surprise that most universities teach Python as an introductory language. Thanks to its simplified, English-like syntax, it allows newbies to concentrate on programming fundamentals, concepts, and good coding practices rather than on the intricacies of the language structure. As a result, students quickly adopt a specific developer mindset.
High speed of development
The clear, concise syntax simplifies and speeds up not only learning Python but building software with it. Additionally, its standard library grants a lot of pre-built features that allow programmers to work with Internet protocols, manage operating systems, manipulate data, or integrate web services with less effort.
As a result, the same program will likely take fewer lines of code in Python than in more verbose Java or C++. This makes it a sought-after technology for software prototyping: You can test and prove your idea quicker (and cheaper) than with other languages.
Development performance is boosted even more by available Python frameworks that provide pre-coded components. Instead of creating everything from the ground up, programmers may capitalize on ready-to-use building blocks.
Among the most popular Python frameworks for rapid web app development are
- Django. It offers nearly 10,000 packages, covering almost every aspect of web app design — database connections, HTML templates, user authentication, CAPTCHA protection, APIs, content management systems, and many more. Facebook and Instagram use Django for their backends.
- Flask. This lightweight, easy-to-set-up technology is categorized as a microframework. Flask lacks many in-built features provided by full-fledged enterprise frameworks like Django. Instead, it gives developers the freedom to structure an app as they like and use third-party libraries of their choice. Flask is supposed to be more suitable for small web apps. At the same time, it fuels large projects such as LinkedIn and Pinterest.
- Falcon. Another minimalistic framework focuses on building high-performance web APIs and app backends. The list of Falcon users includes PayPal and Opera Software.
Python is also a component of the LAMP stack, which stands for Linux, Apache, MySQL, and Python, PHP, or Perl (all dynamically-typed languages.) It provides a standard and mature way of building web applications, saving development time.
Portability and extensibility to other languages
Python is platform-agnostic: You can run the same source code across operating systems, be it macOS, Windows, or Linux. The portability is achieved due to bytecode and a Python Virtual Machine (PVM) that serve as mediators between a developer and an actual CPU executing the program.
Besides that, Python easily teams up with other languages using extensions like Cython for C, Gython for Go, Jython for Java, and IronPython for .Net. They allow developers to mix languages, borrow functionality their main technology lacks, and run the ‘foreign’ code inside their applications.
Versatility plus extensive toolset for almost everything
Python can be applied to a wide range of tasks beyond software development. In particular, it facilitates the work of researchers, data scientists, data engineers, QA engineers, and DevOps specialists. It’s also one of the most popular instruments for financial analysis. The number of Python libraries fueling the above-mentioned fileds and others hits 137,000. Below, we’ll look through the most popular use cases of the language and the tools behind them.
Deep learning and AI. Python leads the pack in deep learning thanks to the vast collection of dedicated libraries. Among them are
- TensorFlow, created by the Google Brain team to train and run deep neural networks (DNNs);
- Keras, working on top of TensorFlow, focuses on user experience and simplifies DNN construction; and
- PyTorch, Facebook’s AI Research lab (FAIR) introduction used to drive computer vision and natural language processing projects.
Scientific programming and data science. Scientists, engineers, financial analysts, mathematicians, and other experts involved in data-driven research are the key users of the Python-based SciPy ecosystem. It contains such powerful tools for data analysis and visualization as pandas, NumPy, scikit-learn, and matplotlib.
Robotic process automation. Python is a go-to language for writing lightweight programs — scripts — for automating mundane business tasks (robotic process automation, or RPA). Examples of such operations are filling out online forms, reading and writing files, creating and removing folders, sending emails and notifications, web scraping, and requesting data via APIs.
Some tools commonly used to build RPA applications with Python are
- Beautiful Soup for extracting specific elements out of XML and HTML files,
- RPA Framework, with its collection of libraries for most common repetitive tasks,
- Scrapy, one of the most popular frameworks to build web crawlers — bots that systematically browse web pages and scrape them; and
- PyAutoGUI to automate repeated mouse clicks and keystrokes.
Test automation. Python has a reputation for a plethora of test frameworks that speed up checking the quality of your code at every stage of the software development life cycle. QA engineers can take advantage of
- PyUnit, part of Python’s standard library;
- pytest, a preferred tool for databases, UI, and especially API testing;
- Locust for load testing;
- Splinter for testing web apps;
- Hypothesis for property-based testing when your code is checked against hundreds of different scenarios; and
- many other tools.
Test automation is a critical element of DevOps methodology, based on the idea of merging development, quality assurance, and IT operations into a single, repetitive cycle to speed up software delivery.
DevOps. DevOps is all about optimization and automation across the software development life cycle, and this is where structured and readable scripts written in Python shine. Many DevOps tools are Python-based, including
- SCons and PyBuilder for build automation (converting the source code into an executable program);
- Ansible for configuration management; and
- Buildbot for continuous integration (CI).
Other popular DevOps instruments feature out-of-the-box support for Python. Among them are a Gradle build tool and platforms for continuous delivery and integration (CI/CD)such as Travis CI, Strider CD (continuous deployment), and TeamCity.
Free technology with a large talent pool and vast global community
Python is open-source and free of charge for everybody, even when it comes to commercial use. Given all other strong points, it’s no wonder that the language enjoys the largest talent pool. As of 2019, there were 8.2 million Python developers while programmers using Java numbered only 7.6 million. Since then, the community has increased even more, with Python keeping the title of the most wanted language among programmers for the fifth year in a row.
There are more than 1,600 official Python user groups across 37 countries, with the total number of members in excess of 860 thousand. You can also get help from peers and enhance your programming skills via Stack Overflow, boasting over 1.8 million Python-tagged questions, a Reddit community of 859,000 Pythonistas, or Real Python Slack chat.
Cons of Python
As great as it is, Python doesn’t fit every project. Here are its key disadvantages to keep in mind when choosing the right technology for your case.
You already know that Python is a champion of development speed. Yet, it can’t boast the same results in speed of execution, lagging behind C ++ and Java.
You most likely remember that the Python program is interpreted at runtime, line by line, instead of being compiled to the machine code in one piece. While this brings advantages in terms of debugging, it comes at a price of the runtime performance.
Another inherent delay factor is dynamic semantics. It simplifies things for programmers, as they don’t need to declare types of variables and can do with fewer lines of code. Instead of the developer, the interpreter has to check and assign types as a program runs, making it slower.
Python uses a mechanism called a Global Interpreter Lock, or GIL for short, that allows only one sequence of bytecode instructions (thread) to be executed at a time. GIL brings important benefits as it
- ensures thread safety,
- enhances the performance of single-threaded programs, and
- simplifies the integration of non-thread-safe C libraries with Python.
At the same time, the GIL creates a bottleneck for multithreaded programs designed to run multiple workflows simultaneously. This prevents you from taking full advantage of modern multicore processors, which can execute several tasks concurrently.
There has been a lot of debate about removing the GIL. However, no feasible solution has been detailed because too many Python features, modules, and packages are tied to it. Besides that, throwing out the GIL would degrade the performance of software with single-threaded architecture.
To overcome the GIL’s limitation, you can use Python’s multiprocessing package that enables the use of numerous subprocesses instead of threads. In this scenario, each process uses its own interpreter and memory space while the operating system schedules the parallel execution of jobs across different CPU cores. In fact, we still use separate threads for every process; while in multithreading, all processes executed in parallel share the same memory space.
But parallelism comes with one big disadvantage: It devours a lot of memory resources.
High memory consumption
Python is often criticized for high usage of resources, even when multiprocessing isn’t involved. Its objects come with a huge overhead and can gobble up ten times as much memory as is needed to store information we actually require.
While Python has a garbage collector to manage memory, it doesn’t return resources to the system immediately after the object becomes unnecessary. Besides that, if your code holds any references on this outdated object, it can’t be deleted at all.
Due to these factors, Python programs tend to run out of memory. Developers have to make an extra effort to pinpoint the sources of the problem and enhance memory management, especially when it comes to processing large amounts of data.
Hassles with mobile and front-end development
No smartphone natively runs Python: native Android app development is done with Java or Kotlin while iOS gets along with Objective C and Swift. Developers can still build for mobile in Python with Kivy and BeeWare cross-platform frameworks. However, these tools are less popular than Microsoft-owned Xamarin, React Native by Facebook, and Google’s Flutter.
Despite all the advantages, Python fails to get traction in the growing mobile market. Why? It consumes too much memory and energy compared to what mobile hardware and operating systems can afford.
“Python is big and slow,” explains Python’s creator Guido van Rossum in his video interview for Microsoft Reactor. “It uses a lot of battery charge, so if you’re coding in Python, you would probably very quickly run down your battery and quickly run out of memory.”
For the same reason, the chances are slim that the popular web backend language will ever dominate on the client-side. Yet, Pythonistas don’t give up. Currently, volunteer contributors are actively maintaining Pyodide, the project aiming to bring Python and its scientific stack to the browser. The tool compiles the Python interpreter to WebAssembly, a low-level language that runs on the web browser with near-native speed.
Python vs. other programming languages
Now, let us take a look at how Python fares when compared to other well-known and high-level languages:
R vs. Python
Both of these languages are open-source and extensively used in data science. And that’s where the similarity almost ends. Inversely to multi-paradigm and beginner-friendly Python, R was created by statisticians for statisticians to run statistical analysis and data visualization. As such, it enjoys a larger ecosystem for data science than Python. Researchers appreciate R for outstanding visualizing abilities: You can immediately illustrate the analysis results with graphs, plots, or charts.
Python focuses mainly on software development and deployment, enabling programmers to run data analysis and machine learning in production environments. Python introduces most AI features prior to R. For now, both languages support deep neural networks, and you can use Python-based TensorFlow, Keras, and Torch for R to build ML models in R.
Java vs. Python
Python and Java have much in common. They are time-honored, platform-independent, high-level languages widely used for backend development. They both support object-oriented programming and compile to bytecode to be run on a Virtual Machine. But Python does it at runtime, while Java makes all transformations beforehand. Another major difference is that Python is dynamically typed, and Java sticks to static typing when the type is assigned to the value once and forever.
These two factors impact how you write and execute code in Java and Python. As we already mentioned, Python beats Java in development speed, as it has clear syntax and needs fewer lines of code. In turn, Java is faster and more efficient when it comes to execution. It uses a just-in-time (JIT) compilation mechanism that boosts app performance. Besides that, Java allows for multithreaded programming — something that Python can’t afford due to the limitations of its architecture.
Java vs. Python code. Source: reddit.com/r/ProgrammerHumor
Python can’t boast of such omnipresence, sticking to the server-side. At the same time, JS pales in comparison with Python regarding data analysis and machine learning tasks. It’s also worth noting that according to the 2020 Python developer survey, JS is the most popular language to be paired with Python.
How to start with Python
Assuming that you decided that Python is a programming language you want to learn and work with, then here are a few steps to get you started.
Go to Python’s official website to download the latest version of the language. There are options for Windows, Linux/UNIX, macOS, and other platforms.
Look through the documentation page where you can find a Beginner’s Guide, Python FAQs, the list of Python books, Python 3 documentation, and other useful resources to better understand and master the language.
Python comes bundled with Integrated Development and Learning Environment (IDLE). However, depending on your needs, you can install and use other IDE — such as
- Thonny for Python newbies,
- PyCharm for professional developers, and
- Spyder for data analytics, data scientists, and engineers. The IDE comes pre-integrated with its essential libraries for data analysis (NumPy, Matplotlib).
Of course, the choice is far wider than that. You can get acquainted with numerous Python editors here. The list of Python IDEs that combine editing, debugging, compiling, and other capabilities is here.
The future of Python, or what about Python 4?
Currently, Python fuels backends of large, widely-known projects like Reddit, Dropbox, Yahoo Maps, Google, Pinterest, Facebook, and YouTube, to name a few. And that’s why the language will hardly ever see a version 4. The Python development team has learned lessons from the previous transition to Python 3. It was a painful period, stretching over several years and taking much more effort than had been expected.
“It’s almost taboo to talk about Python 4 in a serious sense,” admitted Guido van Rossum in the above-mentioned video. “We now have a strict annual release schedule, so after Python 3.10 will be 3.11 and after that will be 3.12, and so forth. We can go up to 3.99 before we have to add another digit. Adding another digit is not completely trivial, but still much better than going from Version 3 to 4.”
Now, the dev team is concentrating on Python’s speed. Notable improvements will come with version 3.11, scheduled for October 2022: It will be much faster than the previous release. “Then we’ll speed it up more in 3.12 and 3.13, and so on,” promised van Rossum. We can only wait and see.