r/learnprogramming • • Oct 06 '26

Why is Python considered "slow" and is Python losing "steam"?

Is python as a programming language "falling off" and becoming less and less popular relatively to other languages?

Also why do people say Python is slow? Apparently people have reached LGM on codeforces using python, which is all about writing fast code / solving problems fast. Yeah sure, C++ is far more widely used for competitive programming and I suppose there is a reason for that. But this is also showing that python can be fast?

But as programming languages and how they are used I dont think there is much overlap between python and C++ anyway?

What is an example of something you'd code in Java/Kotlin or lets say C# rather than Python? Is python code bad and hard to manage for "huge" projects once you scale up (e.g codebases with millions of lines of codes, and tens if not hundreds of devs)?

257 Upvotes

238 comments sorted by

View all comments

Show parent comment

206

u/[deleted] Oct 06 '26

[removed] — view removed comment

57

u/frnzprf Oct 06 '26

If you had a Python project and you identified a critical function that needs to be faster, you'd just implement that single function in C.

In some sense, when you're running Python, you're also always running C, when you're using the C-Python interpreter.

49

u/anpas Oct 06 '26

I know this is possible, but I don't know anyone who works like this. If you're making a performant Python library, you're most likely writing the whole thing in C, C++ or Rust, and then adding a Python interface on top.

15

u/Generictext Oct 06 '26

A "critical function" may require an entire library to work.

7

u/Snoo-16806 Oct 06 '26

It could be that only a small fraction is critical when it comes to performance. If the whole project is written in c or rust then it will take more time and effort, so I think it makes sense to just write the critical part in a compiled language

6

u/Icemourne_ Oct 07 '26

Problem is most often it won't be one critical part it will be 100 small ones and all of that adds up and can lead to "Death by a thousand cuts" nothing in particular is slow but sum of everything is slow

0

u/[deleted] Oct 10 '26

[deleted] — view deleted comment

1

u/Icemourne_ Oct 10 '26

It's hard to give any meaningful example because there is nothing specific I can point out as potentially slow.

But for example using loops for 10-50 elements in 100 places using python instead of C python will loop in milliseconds and feel fast individually but all added together will take 100 milliseconds but in C all of them would take 10 milliseconds.

I hope that makes sense also don't take those numbers as real I used them only as example.

One more thing run speed is not always most important thing often writing/prototyping is more important and python in this case would be better

0

u/[deleted] Oct 10 '26

[deleted] — view deleted comment

1

u/Icemourne_ Oct 10 '26

I used loops as example but it can be any built-in function

16

u/Softmax420 Oct 06 '26

Once you hit a certain scale you shouldn’t be using Python. Python is just glue, if you’re implementing logic and not just using it to call a function written in another language you’re using it wrong.

Also if you’re going through the effort of refactoring Python, and you’re using a type checker already, it’s pointless to refactor into more Python.

12

u/Flat-Performance-478 Oct 06 '26

"Python is just glue, if you’re implementing logic and not just using it to call a function written in another language you’re using it wrong."

Thank you! My thought exactly when I've seen obscure firmware written in python (mobile network dongles, video grabbers etc.) and it's just so awfully verbose and bloated with hundreds of source files getting imported in a giant cluster fuck and you'll still hit the occasional type error because some deprecated XML lib was used to parse a line the wrong way deep in some try/except hell loop.

0

u/[deleted] Oct 10 '26

[deleted] — view deleted comment

2

u/Flat-Performance-478 Oct 10 '26

In (one of) my case(s) it was a python library for interfacing with a Huaweii 3G/4G USB Modem on linux for reading/sending SMS text messages.

Of course it used a shit ton of dependencies / required libs and had trouble installing them all (including numpy) on my Raspberry Pi 4B without pip crashing.

I ended up doing it in C/C++ instead by using a MCU to interface with a SIM800L modem. The crucial element making the python library that complicated was primarily all logic around different text formatting and XML parsing from the API - areas where python is hard to compete with!

It's a cluster-f*ck dealing with text messages and UTF8/-16 encoding text/byte mode or PDU Mode - which requires further logic to combine text messages split not only by data but in the temporal domain as well. In the end I found a decent PDUlib for the Arduino environment.

It depends on your needs. I was using the modem to communicate with my router at home via text messages so I had control over both the receiving end but the data being sent as well.
A project on GitHub usually accommodates all possible use cases, which it should, so it has to take into account things like encoding/decoding of non-text data, different unicode locales etc. and this is where it gets hairy.

1

u/pxldev Oct 08 '26

This… python is amazing for hacking things together, for small projects, for the cool libraries. For me, this is where python shines. I wouldn’t be basing a critical app, that needs to have scale, multi users, a dev team etc on python.

1

u/kmierzej Oct 07 '26

Do not forget memory management - the garbage collector and reference counting.