r/learnpython • • Jun 28 '20

Can anyone explain why we use Python

I keep reading people say things like ‘because Python is built on C’ and ‘Python is much slower than C++ or Go’, ‘Thats why those languages are used to make most popular games’. I also see people refer to Python as a ‘machine’ language, etc etc. So... why use python then if you can do things faster with another language? And why is Python so popular if this is the case? Seems like python is easier to understand for me at least and much easier to read, but is there some other benefit I’m not understanding? Sorry if this had been asked before, I can’t find any direct comparison information between Python and other languages.

EDIT: Thanks everyone! I feel a much better understanding of why python is fast in a different way from other languages, saving programming time rather than computing time. Definitely got the answers I was looking for.

Another edit: Great insights all around. Thanks to everyone taking the time to answer! Looks like I need to do some more research on Cython as I see a few people mentioning it for when speed is required.

336 Upvotes

120 comments sorted by

View all comments

6

u/[deleted] Jun 29 '20

A lot of what happens in programming world is driven by fashion. But, this isn't the only explanation. There's also a network effect, that keeps amplifying preferences of a group of people, once it reaches certain threshold.

This is not unique to Python, this is, essentially, the story of every technology popular today.

To try to trace Python's history back to its origins, at least as far as I can remember it, it would be more or less like this:

  1. Linux, while, officially, GNU/Linux was slow to come up with a decent programming language for system programming (Guile an implementation of Scheme, which is still not 100% there). Even though GNU stands for "not UNIX", it is a UNIX lookalike, and so, it inherited UNIX' Shell. Vanilla UNIX shell isn't a great language... it doesn't have integers or arrays (only ways to treat strings as if they were such) just to give you an example of inconveniences. Not to mention modularity, error handling, and general correction verification as its major problems. Python was in Linux since its very early days, and so got pretty well integrated into the system.

  2. Python had also an easy way to write bindings around native code, so that a lot of libraries would ship with Python bindings already written and available. This made it easy to use for system programming on Linux. Unsurprisingly, a lot of system utilities on Linux are written in Python as the result.

  3. Since Python was there it was tempting to use it for many things. The web industry was, and still is booming. Eventually CGI were replaced by PHP. At that point web entered the era of shared hosting, with LAMP being the default setup for it. However, there was a lot of discontent around PHP as it was awfully primitive and poorly implemented language. Thus, when the demands for sophistication of the back-ends grew, people started to look for alternatives. This was the time many languages jumped on this bandwagon with their webframeworks. Ruby with RoR, Java with Spring, and Python with Django. Python was never the hottest language in web development, but it earned some popularity nevertheless.

  4. Someone discovered that they can use video adapters for low-precision massively parallel computations. But this functionality is too difficult to make available to mainstream languages due to very outdated model of computer and computation they are based on. The much easier solution is to write a library that does this massively parallel stuff, while exposing something that looks like PDP-11 on the interface level. Since Python was so easy to wrap around native code, NumPy was created. And machine learning took off (not because of NumPy, but it carried Python to the new levels of popularity).

  5. There was also another vector that contributed to Python's popularity: it was used in testing / automation because it was used in system programming and already had ways to interface with the system under test.

Put all of the above together, and you get a very popular language, that's in the interest of a lot of people to maintain because their programs depend on it.


Unfortunately, this has nothing to do with quality. Python was never a quality language, never tried to beat any other language on any characteristic... never tried to be the best at anything. Kind of an underachiever language. It just had this fortune to get inserted into many key positions, which ensured its long-term survival and proliferation... the same happened to C, or JavaScript or... chances are that if you've heard about this language, it's more or less the same story.


So, we use Python because it is popular. Popularity isn't just some dumb high-school prom thing. Popularity in this context means money. It is easier / cheaper to hire programmers who program in popular language. It is easier / cheaper to write large programs because many components have been already written and are freely distributed by other people. It is easy to coach new trainees, it is easy to find development tools that support the popular language... The financial advantage is so huge that people don't even attempt to use other, better languages, not even if they know they are better.

So, we use Python, because there's a monopoly on the minds and preferences, that becomes stronger and bigger the stronger and bigger it becomes. :)