r/ProgrammerHumor • • 6d ago • Bravo 1

Meme pythonSlow

Post image
11k Upvotes

419 comments sorted by

View all comments

943

u/ProgramBrave718 6d ago

Python after saying it's name to Rust - "I am known for machine learning. But, devlopers call me slow"

276

u/creeper6530 6d ago

Python is an orchestrator for C/C++ libraries at this point 

128

u/MegaPegasusReindeer 5d ago

The default implementation of Python is CPython. It's always been byte code running C written machine code.  There's even Cython to write Python that compiles into C code.

28

u/FlyingRhenquest 5d ago

Yeah, it's great for that. I built an automated video test system for Comcast back in 2018 that was heavily-threaded C++ code with a Pybind11 API to send requests and retrieve responses to the backend. The system was responsive in real time as long as you didn't saturate the image recognition thread pool.

11

u/Yodo999 3d ago

At any point. Python was always that.

14

u/HeisterWolf 5d ago

This so much lmao. Most code I write is basically Python orchestrating other processes or an FFI to something like rust if it's performance-critical.

8

u/wildjokers 5d ago

Python is just calling out to c and c++ libraries.

129

u/theotherdoomguy 6d ago

Youre known for being a wrapper for the C/C++ applications real developers used to make Machine Learning, you goddamn hack (Ive recently had to start maintaining a python microservice and I'm getting real heated about how shit python is)

215

u/raddaya 6d ago

C/C++ are known for being a wrapper for the assembly code real developers use to make computers do things you goddamn hack

And so on, and so forth

68

u/FalafelSnorlax 6d ago

That isn't quite the same. C/C++ compile into assembly, which means the code is fully converted. Python is typically simulated by an interpreter, so the code itself doesn't compile into any lower-level language. When they say it "wraps C/C++ code", they really mean that instead of simulating the python byte code, the interpreter runs a library that wasn't written in python at all.

28

u/yonasismad 6d ago

Python compiles into byte code.

31

u/FalafelSnorlax 6d ago

Yeah but isn't a lower-level language, it's a machine-friendly format of the language. The main point is that by virtue of being interpreted, it is inherently different to languages like C/C++ or Rust.

12

u/toejam316 6d ago

Inherently whatever the code is at some point "compiles" into the language the CPU uses. The fact it's running in a JIT interpreter doesn't prevent that. If you were insane enough you could absolutely get the assembly equivalent of your python code.

3

u/m0nk37 5d ago

Python loads the C/C++ library that runs the machine learning, python listens for events from the library and delivers it to you. Thats what a wrapper is, there is no byte code actually doing the machine learning through python, python is just the intermediator in that situation.

→ More replies (3)

7

u/nimrag_is_coming 6d ago

Python doesn't JIT compile, and it can't really very easily due to how dynamic it is, ie every time a piece of code runs it might actually run something different depending on what type a variable is etc.

You probably technically could turn it into assembly but then it's basically going to be a virtual machine with abstract types rather than being like actual raw assembly, so you've gained almost nothing compared to just running bytecode in an interpreter.

15

u/i_only_eat_purple 6d ago

CPython (the reference implementation that most people use) has an experimental JIT compiler since 3.13. https://peps.python.org/pep-0744/

7

u/rosuav 6d ago

PyPy JIT-compiles, and CPython currently has a JIT compiler too, although that might be removed.

13

u/Ok-Scheme-913 6d ago

Tell that to the multiple implementations of Pythons that are jit compiled, like GraalPython.

A programming language is just that, a language. Sure, some are easier to compile to efficient machine code than others, but there is no law forbidding a sufficiently smart compiler to work 3 days and prove that this ultra efficient simd machine code is the same program denoted by python's semantic laws, and thus that will be the compiler output.

4

u/nimrag_is_coming 6d ago

Yea at runtime when it's interpreted, and it still has to do a lot of checks and extra stuff whenever it runs a line of code because it's still not machine code

→ More replies (7)

13

u/[deleted] 6d ago

[removed] — view removed comment

→ More replies (2)

8

u/rosuav 6d ago

Assembly code is known for being a wrapper around weird quirks of atoms and electricity, which real physicists explore by simulating it in Python.

→ More replies (3)

6

u/Ok-Scheme-913 6d ago

Well, do you (live!) rewire your house to turn on the lamp in the kitchen, or add a switch that you can press and have it turned on/off instantly?

Sure, it may be "more efficient" to have a single real wire go to the lamp directly instead of the inefficiency of a switch. Oh and I don't like touching live wires either (heh, this analogue works quite well)

→ More replies (35)

9

u/DarthCloakedGuy 6d ago

Nothing made me love Python like learning C# and C++, ngl

5

u/FabioTheFox 6d ago

C# is a lovely language to work with, C++ too if youre willing to do some initial setup to create your perfect template repo

→ More replies (5)
→ More replies (2)
→ More replies (1)
→ More replies (3)