Why is Python so popular despite being so slow?

Let me reframe this question using different technology. Why are Toyota Corollas so popular despite being so slow? They're obviously much slower than rocket powered aircraft! Things just got crazy, right? Let's do some math to prove our point about how slow Toyota Corollas really are when compared to rockets.

The nearest grocery store to our house is HEB (if you know anything about Texans and our love for local stores you will have definitely heard of HEB and Whataburger). This HEB is 2.6 kilometers (1.6 miles) away from our house. The X-15 Rocket travels at 7,270km/h (4,520mph). The maximum speed of a Toyota Corolla is 190km/h (118mph). This means that an X-15 will get me to HEB in approximately 1.3 seconds while the Corolla will move at a glacial pace to get me there in 49.3 seconds. That makes the Corolla 38 times slower!

But Seth, you're being ridiculous! Everyone knows that this example is impractical! When we use the example of a car vs. a rocket ship the absurdity is very clear: rocket ships need launchpads and maintenance crews and ROCKET SCIENTISTS! Cars are obviously a better choice when compared to rockets for going to the grocery store. But, what about when we're talking about a cloud-based ETL microservice vs the data layer of an iPhone app? Does everyone understand the trade-offs among programming languages? Do most computer programmers understand these trade-offs?

Now, back to Python. Why would the Toyota Corolla of programming languages be so darn popular? Well, probably because it's the Toyota Corolla of programming languages! Python is simple, straight-forward, ubiquitous; it is a general-purpose scripting language that doesn't lock the user down to any specific framework or paradigm. Don't be fooled, this wonderful flexibility come at a cost - raw speed. I don't think this speed-for-flexibility decision is a bad thing. I feel like this makes Python a great language to have readily available to accomplish quite a few very useful programming tasks.

Instead of nit-picking Python's speed at iterating over 10,000 characters or propogating the GIL myth I think it'd be more valuable to simply understand where Python's value is. Using the Corolla and Rocket comparison, both do have uses and in most circumstances one is a far better choice than the other.

Where Does Python Work Well?

If you are building an application that runs on a server (or better, a web service), connects to a database, and returns a modified (read: json) response; then Python is an excellent choice. The majority of your run time will be waiting for network I/O and not CPU number-crunching. It is highly unlikely that web systems run in such a manner that shaving milliseconds off of the runtime is more valuable than optimizing network speeds or database queries.

If you are learning to program, I feel like Python is a fantastic choice. The built-in REPL is great for testing out ideas and helps get you up-and-coding quite rapidly. Python also has extensive documentation and, because of the age of the language, many engineers who have been programming in Python for decades.

If you are working on Machine Learning models Python is a great general-purpose language with a very lively community, robust set of modules, and an army of Ph.D.s pushing human knowledge forward.

The numpy module has dramatically increased Python's ability to do raw number-crunching; this is a big reason Python is so useful in the Machine Learning space. The push for awesome math skills has helped made Python a great language for building systems that count things such as massive financial batch systems. Accountants rejoice!

Where Does Python Fall Short?

Python has never been my first choice for embedded, or real-time systems. These tasks are much more suited for languages that live very close to the architecture being worked on.

Python does not fit in the Mobile Software Development ecosystem very well. With Android and iOS dominating that space, it is prudent to "live in the walled garden" for each platform.

Python does not hold a candle to Desktop Gaming Software. In an industry where success literally depends on the raw speed of the software, Python does not and never was meant to compete.

Instead of giving you an answer than can be easily memorized and repeated on demand, I hope that I have instead equipped you with better knowledge of when - and when not - to use Python.

Happy Coding!