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

40

u/flyingfox12 Jun 28 '20

Some other things that haven't been said here:

Python has lots of modules, you don't need solve as many problems because some one else already has.

Connected to the one above, python has a huge user base, so modules you rely on will be somewhat supported.

Python has a critical mass of users across use cases. So you can jump in to using it whether you're building an IoT device, working as a devops CI/CD specialist, or doing big data analysis with machine learning.

IMO python's biggest issue is GIL, and it's that alone that has stopped it from going further than it already has. That's why Go is a very good language to also work with.

8

u/scrdest Jun 28 '20

GIL is not even a Python problem, it's a CPython interpreter problem. It wouldn't even be a problem if all the attempts rewrites thus far didn't crash and burn. The overhead for the dynamic stuff is unfortunately real no matter the interpreter, though.

8

u/PricePadraic Jun 29 '20

Do languages like JavaScript, Go, Ruby, C#, etc etc... not have the amount/usability of modules? I know a tiny bit of JavaScript and mostly only have learned in Python thus far. I guess I just expected all languages had modules to download and use... sounds dumb now that I thought that.

6

u/kor_the_fiend Jun 29 '20

Different languages tend to excel in different areas, module wise. Python excels and is the clear leader in certain areas, such as data science/mathematics due to strong user support and community development of modules relates to those areas. At the end of the day, it is up to the users/community of a particular language to create the modules that we will all use.

3

u/flyingfox12 Jun 29 '20

they do, python does that very well, with lots of useful modules being constantly enhanced by big players but available free.

4

u/Random_182f2565 Jun 29 '20

Pandas, matplotlib, openpyxl, Django, pyautogui, sklearn, etc Python simply never ends

2

u/AsleepThought Jun 29 '20

IMO python's biggest issue is GIL

gonna have to disagree with this one, I find that the biggest issues with Python are by far the library ecosystem, and the dynamic typing.

The fact that there are so many modules out there becomes more of a curse than a blessing, when your dev's start including random arbitrary modules to do simple things that they are too lazy to write a little boilerplate for, now you start accumulating a laundry list of dependencies, next thing you know you've got dependency hell, you need virtual environments, which lead to containers, now your 500KB Python program needs a 800MB container in order to run, not to mention the man hours needed version-locking all the libraries in the container, setting up and maintaining your own container registry, upgrading one dependency breaks another, etc..

And the simplicity of the code turns your projects into messes as they grow larger. Dev's start writing chicken scratch functions where you cannot tell what data type or data structure any of the input or output parameters are, testing is an afterthought, etc..

Python gives inexperienced dev's plenty of rope to hang themselves with, and bring you with them. Not that other languages are immune either, but this is far, far more severe than GIL and other languages handle this much better.

1

u/flyingfox12 Jun 30 '20

I agree with everything you've said. Really insightful.

My response was more pointed at "why we use python" and not why we should. So when I wrote about the biggest issue in python being GIL I meant for getting started. If you have a project you know will need to scale GIL will stop you from starting with python.

1

u/painya Jun 29 '20

I believe that they’re working on a solution to GIL too! Sub-interpreters are what they’re calling it.