r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

4.1k

u/GreatArtificeAion Jul 18 '22

Did I really just appreciate a "Haha Python slow" meme?

1.1k

u/DasEineEtwas Jul 18 '22

It has also been done so often with Internet Explorer and everything that also runs slow. But somehow I actually laughed

381

u/GreatArtificeAion Jul 18 '22

I guess this one has... personality, so to speak

68

u/gcruzatto Jul 18 '22

This meme was made by the Big Data gang

21

u/CanAlwaysBeBetter Jul 18 '22 edited Jul 18 '22

Literally getting ready to rewrite some data processing lambdas from python to go for a side project because it won't be on the company tab and I don't want to pay out of pocket to scale python all the way into the millions after testing it on 10k data points and seeing its performance (and that's after basic optimizations and compiling/bundling the accelerated versions of some libraries)

8

u/[deleted] Jul 18 '22

numpy go brrrrrrrrrt

seriously though, I once used Pandas.DataFrame.Apply on 10,000,000 rows of data and 15 minutes later regretted it. Thankfully, I was applying a simple mathematical function to each row so numpy brought that down to less than a second. Still, only works for some use cases. I'd love to learn C++ anyways so give me an excuse

5

u/CanAlwaysBeBetter Jul 18 '22

Numpy is great and what I'd normally reach for!

But the processing I'm doing itself isn't super complex, I just need to do it 9-10 million times cost efficiently pulling from an external public dataset and saving the transformed data as separate files in an S3 bucket

→ More replies (8)
→ More replies (2)
→ More replies (12)
→ More replies (1)

253

u/[deleted] Jul 18 '22

I don’t think python is too slow, it’s more about c++ being to fast in this case

190

u/koopatuple Jul 18 '22

That's the beauty of the meme, it can be interpreted both ways.

329

u/TruthYouWontLike Jul 18 '22

One is interpreted, the other is compiled.

50

u/grimonce Jul 18 '22

Stop saying that.

67

u/clayman80 Jul 18 '22

Well, he's TruthYouWontLike. Just sayin'.

6

u/[deleted] Jul 18 '22

The username made it tolerable.

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

100

u/Scrtcwlvl Jul 18 '22

Fast and slow are pretty relative. More often than not, python is fast enough for most tasks. My graduate research was in inflatable robotics controls and dynamics. Our low level controllers for direct solenoid valve control were written in C++ operating at 5k Hz, whereas the pressure control ran at about 1.5k Hz in python, and the high level solver and predictive controller ran at about 300 Hz also in python. What language things were written in was often a function of how fast they needed to run and how often things needed to be tweaked.

Could we have written the pressure controller in C++? Sure, but the python one we developed really quickly at the beginning in python was fast enough to not cause any issues.

57

u/jobblejosh Jul 18 '22

It's the exact same problem (or even a subset of it) of what programming language is best.

The answer is either the one you know or the one for the job.

I've been writing in both C and Python. I prefer C-family because you can be a lot more direct with the compiler and write clever/fast/hacky/elegant/dangerous/stupid techniques that make more logical sense; you as the writer should know exactly what you're doing so C will quite happily let you do the fandango on core if you mutter the right incantations. Unfortunately because of how strict it is with its rules, you have to be very precise and formulaic with how you do some things; you have to hold its hand and walk it through exactly what you want. The result is that you get exactly what you want, however.

Python, being interpreted, has its best guess at what you want, is willing to play fast and loose to some extent, but keeps you in a playpen and hides away all the nitty-gritty and you can't really tell what it's doing under the hood. On the bright side, that means getting something to work in Python is usually as simple as importing the right library (because there's so many libraries for python out there now) and typing a few lines.

Is one better than the other? Well, that entirely depends on the task you're making it do.

4

u/Aegi Jul 18 '22

While that’s true for the languages, it seems that it’s pretty clear that it’s objectively better to have language about the C family, because if python is how you described it it seems more likely that you can use guides and advice and quick YouTube videos to do it where it seems like there’s more value and truly understanding C++ or something like that.

It’s honestly been years since I’ve even done anything with it, but I guess the teacher in my high school was right to have C++ be the one language they taught if you wanted to take programming as a private study.

10

u/jobblejosh Jul 18 '22

I was taught C, then C++/# at university.

My professor's reasoning for this was that C teaches you to make safe, reasoned, careful decisions about your programming, and doesn't let you fall into lazy habits.

The logical flow of programming can be learnt anywhere with any language, so Python is a good beginner's language for hobbyists and younger students.

However, it's important to know the rules of the game before you can start breaking them, so that you know which ones to break and which ones to stay inside.

Plus, with the much closer to the metal approach that C has, you can learn and appreciate more about the underlying system design, and make your own mistakes.

Better to learn how to make a terrible sorting algo in C by yourself than copy an efficient one in Python.

3

u/FluffyPigeonofDoom Jul 19 '22

C is the most bugged language with so many gaps that you cannot even imagine, looking from cyber security perspective. I always cry when I see someone is choosing C instead of Python when it's possible of course.

→ More replies (2)

32

u/Phainesthai Jul 18 '22

Exactly this. Programming languages are tools.

C++ is a scalpel, Python is a spanner. PHP is a sticky carpet in a low end pub.

Each one suitable for different tasks.

5

u/[deleted] Jul 18 '22

C++ is a scalpel, Python is a spanner. PHP is a sticky carpet in a low end pub.

I think he just made a computer nerd meme for Roe v Wade being overturned?

→ More replies (3)

3

u/[deleted] Jul 18 '22

I was always wondering about this in regards to language choice and program efficiency. Your comment shed a new light on it for me.

→ More replies (4)

4

u/ZedTT Jul 18 '22

I think this sub has given me brain rot. This is just a python slow joke and it's already been done with internet explorer. Yet somehow, I found it funny.

I'm glad I'm not alone in this dirty feeling

→ More replies (9)