(Like this article? Read more Wednesday Wisdom!)
Before I get into the topic of this week’s Wednesday Wisdom I would like to take a few moments to remember Bram Moolenaar, author of vim. Last week I received word that Bram passed away on 3 August 2023. I worked with Bram in the Dutch Unix User Group (NLUUG) and after that we were colleagues at Google in Zürich for over ten years. Bram was a gifted software engineer and an extremely nice person. I won’t boast that we were close, but we knew each other, and I will miss his snarky comments on my Facebook posts.
Python regularly gets roughed up by people who think it is a terrible language and nothing real or important should ever be written in it. These people are wrong. As one indication of that: Python has recently been gaining in popularity as it is an indispensable glue language for ML and AI frameworks. Outside of that space you can code Python in calculators, robots, and even in embedded devices. Every year, hundreds of thousands of people learn Python and many professional software engineers use it. I use it! Surely all of us cannot be all wrong?
Let's start by recognizing that popularity is in itself not a sign of quality. Java, the music charts, and the outcomes of free and fair elections regularly showcase this sad fact 🙂. But things that are actually bad have a habit of getting replaced by something better. Without leaving the letter C, that's why CORBA is mostly gone, C is still here, suckers running Cool:Gen are in trouble (the Dutch IRS), and COBOL is still going strong 🙂
The reason Python is still here (and Pascal is mostly gone) is easy to understand: Python is amazing!
Not that Pascal is bad. I love Pascal. But I wouldn’t necessarily call it amazing.
For quite some time I have advised people to pick up Python if they want to learn how to code. Its unassuming syntax, lazy typing, expressiveness, and flexibility, define a language that makes it easy to get something simple working fast, even if you don't quite understand exactly what is going on. This is essential for beginners because it affords quick successes, which is important if you want to keep people motivated. This is by now widely recognized, as a bazillion bootcamps, “learn coding” books, and online coding courses use Python as their language of choice.
Python really shines in the "casual coding" category, where you need a quick solution to some tactical problem. These programs typically are run only a handful of times under close supervision of a human and do not need to survive the ages or scale to handle all the world's data.
Recently I needed to parse a few hundred documents to find all the "fields" in them. These were found in the text encoded between brackets ("Dear [first_name]"), in UPPER CASE, marked in yellow, or indicated in a some other way. Python is perfect for this. There's a great and easy to use library for reading Word documents, and between Python's native data structures and powerful data manipulation you can quickly do the needful.
Another area where Python is super useful is as a glue language. These are use cases where you need to write a few statements to get data ready for input to a library and then perform some manipulation on that library’s output. Years ago I took a computational photography class and we used Python to script the OpenCV library together. With only a few dozen lines of Python and some calls to this powerful library, we were able to create super cool effects.
Like this one, or this one. In that last one, as you zoom in, you will see mini versions of the overall image 🙂
Today the primary application of Python-as-glue is in machine learning and artificial intelligence. Data scientists use Python and powerful frameworks to analyze data and create training sets and models. The hard work is done by libraries written by computer scientists, often in C or C++; these engines are then glued together by code in Python that can manipulate the available data into the right format and store it. Using some data and a few lines of Python, everyone with only a modest understanding of data and Python is able to generate predictions. For sure there are plenty of dangers in there, but it speaks to the power of Python that this could be made so simple.
What makes Python amazing is that it is not only easy to learn, but it is also very powerful. That is the real genius of Python. And that power is not at all obvious from a cursory first glance at the language.
If you look at C++ and Java it is immediately obvious that these are huge complex and powerful engines. In both of these languages, if you don't know much but want to do something simple, you need to climb a mountain of complexity and overcome significant syntax hurdles. I taught programming courses in both of these languages and I can personally attest to the fact that they are difficult to learn. In Java, even after a week of lectures and labs, people were often still not able to write a simple program that used Java's basic features correctly. In C++, after a week of instruction, I would throw a slide on the overhead projector with a twenty line C++ program and ask them what it would print. No student ever got it right (key concepts tested: Virtual base classes and order of construction).
Python is the opposite of these languages. It has an unassuming simple syntax and a handful of features that are RISC-like in nature: Each of them is simple to understand but they can be combined into very powerful pieces of code that are still easy to read.
Python often gets a bad rap because it is possible to write bad code in Python. That is of course highly unfair. Real programmers can write assembly code in any language. Python has all the features you need to write good code that performs and is easy to debug and test. If you can’t do that, maybe you are just not a very good software engineer?
Python is amazing because it is elegant and powerful and very well suited for a large number of use cases. Every software engineer runs across these use cases and so every software engineer should know Python so they can use it when the need arises, which turns out to be often.
The last thing to remember is that you never (only) choose a language, you choose an entire ecosystem. The Python ecosystem is great, which is another reason to choose Python for your next project.
So, don't get discouraged by haters. If you have a Python shaped problem, use Python! Don't use something else for fear some muppet tells you Python is terrible. They are well known to be idiots who don’t know what they are talking about.
Python is amazing. And, to boot, it was invented by a Dutchman!
P.S: Biggest news in the Python world last week: The Global Interpreter Lock is out!
🙄
Thanks for retiring the GIL, folks!