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

1

u/Dogeek Expert - 3.9.1 Jun 29 '20

A program written in C will take you a week to build, and a second to run.

The same program in Python will take a day to build, and an hour to run.

The saying goes 'time is money', and it's exactly why python is more popular than faster languages. Companies would rather pay someone for an hour of work rather than a week. There are a few exceptions though :

  • The program is meant to run billions of time. You want to squeeze out any performance then.

  • The existing code needs a specific language (lots of legacy code use old technologies, older versions of Java, Perl scripts, PHP and COBOL). You kinda have to conform to the existing codebase then, unless you want to rewrite everything.

It's a cost analysis problem. What's cheaper : rewrite the codebase in a new language ? Spend months of dev time for improved performance ? Spend a few days for a PoC in python or JS at the cost of a less performant app ?

Especially now, the balance is skewed towards higher level languages, since processing power is so cheap (at least compared to a programmer). I can rent a dedicated server for less than 500$ a year. My yearly salary is 42k (and it's on the low side). It's just cheaper to spin a few extra servers to spread the load of a less performant app.