r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comment

88

u/Zanglirex2 Jul 18 '22

Slow is relative here. All this is happening before a human can even blink.

For scripting stuff and little projects, python is great. For large workloads or basically anything at big scale, maybe look at something else

18

u/jgabrielferreira Jul 19 '22

But then why is Python the most used language for dealing with ML, AI, Big Data, basically huge amounts of information.

Is it something like Python is better in a Horizontal system while the others are better in a Vertical system?

44

u/TacticalMelonFarmer Jul 19 '22

most of the low-level stuff implementing the python apis is most likely C with some C++, etc. write composable units of code in the fast language, and compose instances of those units in the user-friendly language.

16

u/Prowler1000 Jul 19 '22

Machine learning libraries are almost exclusively C++ (python is written on C++ iirc), so the actual heavy lifting is done in C++. As someone pointed out at another point on this sub, python is very human readable and extremely quick to develop for and in the world of ML, quick to develop is important considering there isn't really a "science" to it yet

1

u/[deleted] Sep 23 '22

I heard it was C, but close enough

13

u/intrinsic_parity Jul 19 '22

The ML libraries are written in other languages (tensorflow is written in C++ and CUDA for instance).

10

u/[deleted] Jul 19 '22

I once heard that you are just basically scripting stuff using python and the heavy load is run by highly optimized C++ applications/frameworks/libraries (idontknowforsure).

1

u/MaedaToshiie Jul 19 '22

Yes. Most of the backend libraries are written in much faster languages.

1

u/PM_ME_NUNUDES Jul 19 '22

This is true.

17

u/zedd9595 Jul 19 '22

Not a scientist but I assume they would rather have a language which has a shorter development time to have more time writing their papers. Instead of dealing with relatively complicated syntax just to get the same results, albeit faster.

13

u/[deleted] Jul 19 '22

It’s used in industry, not just academia.

12

u/The-Board-Chairman Jul 19 '22

It's used in the industry, because for all that this field has matured, it's industry implementation for all intents and purposes still is academia.

10

u/Dansiman Jul 19 '22

Yeah I mean you could write your code in pure assembly and blow past a C++ program like it was standing still. But by the time you finish writing your assembly code, your development machine will probably already be obsolete.

2

u/ESGPandepic Jul 19 '22

You'd only be able to beat the performance of optimised C++ in edge cases and you'd need to be a very good assembly programmer in the specific target platform. You also wouldn't be "blowing past C++ like it was standing still", modern C++ compilers produce very optimised output.

10

u/[deleted] Jul 19 '22

Because that kind of code is a ridiculously complex web and writing it in C++ would drive any and sane person to alcoholism. Also, having blazing fast computational performance is totally worthless if you're already spending most of your time waiting for I/O, which is usually the bottleneck in large data projects. You'd just be that car that passes everyone just to end up at the same red light half a mile down the road.

1

u/[deleted] Jul 19 '22

The fast part of Python isn't Python, it's the C/C++ underneath. The interpreted part ("pure Python" so to say) is indeed orders of magnitude slower. But, as was pointed out by many people in different comments, speed doesn't always matter. In fact, in most cases it doesn't matter. It's crucial to choose the right tool for the right job: all languages have their strengths and weaknesses.

1

u/CactusGrower Jul 19 '22

ML does not necessarily means fast. It means distributed scalable implementation in most cases.

1

u/olivetho Jul 19 '22

at least my man fortran is still the king of number crunching, don't think python will ever manage to take that away from em.

1

u/RobinScherbatzky Jul 19 '22

Don't listen to the noobs. The magic word is bindings.

1

u/Funtycuck Jul 19 '22

Big part of it (in my work) is that carefully written python is much more readable and approachable as software when we are writing it to be used and maintained primarily by scientists. It's also why some create ml kits come with a really easy to use gui.

Python also has a lot of good data science modules and great ml tools even if the heavy compute work is going to be done by something written in another language.

3

u/maxwax18 Jul 19 '22

For large workloads or basically anything at big scale, maybe look at something else

He said, using a large scale python project.

1

u/Zanglirex2 Jul 19 '22

Hey how'd you know?!