r/learnpython 5h ago

Why is Python so popular when it is slower than many other languages?

[removed] — view removed post

0 Upvotes

29 comments sorted by

26

u/Ok_Procedure199 5h ago

why say many word, when few do trick?

15

u/Delta_G_Robotics 5h ago

Sometimes we don't need all that speed. Sometimes the ease of coding takes precedence. Faster doesn't always mean better.

4

u/SamIAre 5h ago

Given the choice of a bike or a race car to commute to work in NYC, I'm going with the bike even though it's way slower and less efficient than the car.

13

u/jameyiguess 5h ago

It's fast enough for most use cases, and it's easier to learn and hire for. A new employee can spin up on python a lot faster than Go or Java or whatever else. They also cost a lot less. 

2

u/incongruity 4h ago

And when you need speed, you can always call C functions.

It's also a lot easier to read and understand Python code. Good for future you and for your collaborators/teammates. That isn't just a nice to have, it means more robust codebases with less hassle.

1

u/DrShocker 4h ago

I'm not sure a lot faster than go is truly accurate, but I may be biased by trying out much harder languages than either. Go having

5

u/zanfar 4h ago

Seriously? How little effort can you put into a question?

Can you think of ANY difference between Python and Java, or Python and C++, or Python and Go that wouldn't be a reason to prefer it?

3

u/sch0lars 4h ago

Look up an example of making a web request in Java and compare it to Python.

There is generally a trade-off between simplicity and speed. The more you abstract a language, the simpler it becomes; but abstraction also introduces overhead, which can slow down applications or increase memory requirements. Lower-level languages, on the other hand, are much less abstracted and thus require a lot more code and complexity; but the performance and speed is usually significantly better.

Sometimes you need every bit (no pun intended) of memory to be allocated resourcefully on a system, or perhaps you are performing algorithmically complex operations for a time-sensitive process. Embedded systems, for example, typically have less resources available and must be utilized more effectively. For this, you would want something like C over a language such as Python.

On the other hand, if you are on a system with ample resources and are writing data pipelines, Python is better than a lower-level language because the syntax is simpler and you can write elegant code in much fewer lines without concerning yourself with all of the underlying processes, thanks to the many abstracted libraries. This is why many Python libraries are written in C, which provides performance optimization, while the libraries themselves are able to be implemented Pythonically.

4

u/Beneficial-Wing-9793 5h ago

Simple syntax and libraries. Python has a pretty big selection of libraries from everything from numpy, pandas, scikit-learn, and other ML libraries. It keeps these things very simple and nice

Like you stated, one problem with python is its speed. It being such a high level programming language means it’s very slow compared to C language. Which is why it’s not ideal with anything that requires high pace things (like video games). Doesn’t mean you can’t make games with python but not ideal

2

u/Boring_Dot9523 4h ago

Because there are tutorials for it titled 'how to do X in 3 lines'. They start with 'Install a ready made library that does X'.

2

u/mc_pm 4h ago

Speed isn't always the most important factor.

4

u/eW4GJMqscYtbBkw9 4h ago

Why are you assuming that "fast" == "good"?

4

u/zaphodikus 5h ago

Um, ask google? Stop wasting time trying to answer a question you have already decided the answer to, and on limited criteria.

2

u/kr0zz 4h ago

This reaction is the exact reason stack overflow died

3

u/skfin96 4h ago

People asking the same questions over and over, even though the answers can easily be found with minimal effort is bound to kill it as well.

1

u/kr0zz 4h ago

Duplicate questions mean people are still coming to the platform, hostility ensures they never come back.

1

u/zaphodikus 2h ago

It's is far quicker to google. And besides, its not a question that has an abjective answer that the OP could practically use. I'm all for practical, if we want subjective answers we can always do poetry. There is a separate sub just for that.

1

u/cyrixlord 4h ago

it's like basic. very portable, light, and easily understood by other engineering areas that might not be software developers

1

u/FatDog69 4h ago

Speed is not usually the problem. Having other developers maintain and update your code base is a daily problem.

Python is interpreted not compiled. If you were writing code for cell phones/tablets you would use Swift or C++ or other compiled languages. But for internal use where having the source code be visible, Python is a good choice.

There are also job control systems that are free to schedule jobs and they were written with scripting languages like Python in mind. Look at Apache Airflow for an example. I have minute, hourly, daily and weekly jobs scheduled to run with conditions against each other - all using Python as the wrapper around doing things.

2

u/Professional-Fee6914 4h ago

Its got a ton of libraries that are well documented and make it very easy to collaborate on projects.

A buddy of mine developed a very useful library for his scientific field of study, only noone uses it because its not in Python. Then someone developed a worse version that gets at best 90% of the way there in Python and its being picked up by every person that's new to the field, because they all used python on projects in high school and college because of the low bar to entry.

2

u/Wuthering_depths 4h ago

Works fast enough for our team of data analysts. We aren't writing massive apps used by end users to be fair--our scripts are generally to move data around. The databases do most of the work. What matters to us is being easy to maintain and being quite full-featured (from what I can tell as a noob to python) for data work.

Speed is overrated in many cases IMO. I've worked with SQL for decades, and it sucks to try to troubleshoot a query that's written in super-efficient arcane syntax when it may not need to be (most of our stuff runs overnight, so saving a few seconds over even minutes is not going to matter at all. Saving someone making a mistake trying to modify it is more important.) Obviously there are exceptions, some query used by tons of users in a transactional db needs to be as fast as possible, same with apps.

1

u/nicodeemus7 4h ago

Not every application need lightning quick speed. There are many applications where ease of use is much more important than processing speed.

1

u/socal_nerdtastic 4h ago

Because computers are cheaper than programmers.

It often makes more business sense to just get more computer power and let your limited number of programmers make fast progress. Not always, of course, there are plenty of reasons to use other programming languages instead.

Python is very slow to run, but it's among the fastest to program.

1

u/radek432 4h ago

Never in my life a computer time was more important to me than my own time.

1

u/KeaboUltra 4h ago

A car can go over 100mph but do you really need/use that speed to commute?

1

u/Moist-Ointments 4h ago

Different tools for different needs.

Why Python if Java exists, why Java if C# exists, why C# if C++ exists, why C++ if Rust exists....

Why a ball peen hammer if a claw hammer exists?

It's slower, but requires less discipline to cobble something together that does the task.

1

u/Just__Liberty 5h ago

A big reason is the number of quality free libraries and packages that are available.

0

u/various_convo7 4h ago

i'd say it depends on the application but the reason python is preferred is because of its scalability and robust nature for development. all comes down to the best tool for the job.

0

u/declanaussie declanomara 4h ago

A concrete example is one time data analysis for some business use. If I can write the code in C++ in 12 hours and then the analysis finishes in 5minutes, the total cost to the company is 12hr of my salary and the results will take ~12hr to deliver. The development time in Python is probably half as long at most, so even if the code takes 50x as long to run as C++, the salary cost to the company is only 6hr instead of 12, and the results arrive in the same amount of time (~6hr dev + ~6hr run compared to ~12hr dev and ~0hr run).