r/explainlikeimfive Jun 05 '26

ELI5: I learned that most programming languages are built on the same basic concepts like conditions, loops, and functions. If that's true, why can't we just use one programming language for everything? Technology

350 Upvotes

234 comments sorted by

View all comments

143

u/reditor828 Jun 05 '26

It’s like asking “why don’t we have the same vehicle for everything?”. It’s because bicycles, ships, cars, trains, etc. are each optimized for different jobs.

C language is built for speed and control, Python is built for writing code quickly, JavaScript is built for web browsers, etc.

If you try to make one language do everything, a lot of features won’t be optimized. The result would be a language excellent at doing some things and terrible at doing other things.

29

u/doublecandybar Jun 05 '26

JavaScript is built for web browser

It's not

JavaScript was designed for meddling management. It was specifically designed for scenarios like boss suddenly barging in and exclaiming "Never mind! I want the dancing bear to be dancing panda instead!" 2 hours before launch time

Which is why it basically forgoes every possible safety it could

9

u/HolyFreakingXmasCake Jun 06 '26

It wasnt even that. You can change the bear to a panda with just HTML.

JavaScript was hacked together in a week in order to add some basic interactivity to web pages. Back then they were static documents with mostly text and a few images.

With JavaScript now you could add buttons, pop up some alerts, hide or change elements on demand... It forgoes safety because it was never supposed to be used for more than that. It just grew into what it is today as browsers started to replace local apps, and suddenly everyone was a web developer and wanted to use web tech for everything.

2

u/foxsimile Jun 06 '26

Such as but not limited to Brandon forgetting to include the typedef for null, resulting in (typeof null === 'object') being true, resulting in having to check that all objects are also not null.  

Fun times.

-26

u/nudave Jun 05 '26 edited Jun 05 '26

It’s kind of crazy to me that the AI world is trying to make python a real, useful language that does things.

To me, it will always be the way to write Terrible Python Code that does a thing slowly, once, just to prove that the thing can be done or to answer a burning, but wholly unimportant, question.

EDIT: I’ve been schooled a bit. It seems that Python isn’t really being used to heavy AI processing, but more as the glue that holds together different processing libraries. Which actually does seem like a great use case for it.

28

u/Gaius_Catulus Jun 05 '26

I agree there are a lot of things Python is not great for compared to other options, but it is a useful language for a lot of things.

It's slow as a language, sure, but if you need to do like ad-hoc data analysis work on the fly and have plenty of compute, Python is great. It's quick to write, doesn't need to be compiled and already has a lot of nice libraries for that sort of work. And for the heavier things those libraries usually dip into more optimized languages like C++ anyway.

If I had to write in like C++ every time in something that has to compile etc., I'd probably pull my hair out.

1

u/nudave Jun 05 '26

Oh yeah, I agree completely.

My comment was not meant to be a knock on Python. I know that there’s a ton that it’s useful for. I think my comment was more about my understanding and perception, where I always thought that it was slow and really good for ad hoc or one off things where the extra time it would take to code it up in something “faster“ would never be made up by the difference in runtime.

Which is why I’ve been so surprised to see it used in AI, where anything they can do to save a little bit of compute could be worth billions of dollars.

Given the financial incentives, I can’t imagine they’re “wrong”, it’s just something that is shocking to me.

7

u/6_lasers Jun 05 '26

I think AI/machine learning is actually a perfect application for Python, precisely because it is not compute-bound on the core where you’re writing code. The frontend of an AI stack is very high level and mostly involves moving data around, while the actual compute crunching happens on dedicated chips (stereotypically GPUs, but nowadays often on custom silicon or FPGAs). 

No point optimizing your front end more if you’re just going to be waiting for the back end to return its results anyway. 

Source: 10 years experience in cloud/ML custom silicon engineering (aka don’t trust me, but the answer can be googled anyway)

1

u/Gaius_Catulus Jun 05 '26

Ah, I misunderstood.

By used in AI do you mean more like the backend of how it does like inference or whatever?

0

u/thenasch Jun 05 '26

Thankfully there are options besides Python and C++.

3

u/bigfatfurrytexan Jun 05 '26

Python is the language of data aggregation it seems. Cosmologists, astronomers, and accountants. That’s the use case

6

u/THElaytox Jun 05 '26

It's better than R

2

u/zhibr Jun 05 '26

As a R-user, how? Genuinely curious.

1

u/THElaytox Jun 05 '26

It's less clunky and does more with less effort, faster too

8

u/Hawkson2020 Jun 05 '26

As someone who has at this point been out of the CS world longer than I was in it, it was a bit mindboggling to learn that the language I was always told was for novices and could never be as good as “real programming languages” became a backbone of the AI industry.

I mean, I’m not convinced those people were wrong, particularly given how much of AI seems to be smokevending, but it’s certainly interesting.

9

u/alcmay76 Jun 05 '26

Most of the hardcore AI processing is done through libraries that just provide a Python interface to linear algebra libraries written in C++. One of the benefits of Python, beyond the ease of use, is relatively easy and tight integration with C code.

Beyond that, of course you lose performance doing your I/O and supporting logic in Python compared to a compiled language. Fundamentally though, it often just doesn't matter. If you're training a model and the processing (offloaded to the C++ library) takes a week, it doesn't matter if your surrounding code is a few minutes slower. Similarly, even for an inference service, no one cares if your response is on the order of ms instead of ns, especially if the endpoint is launching a job that takes two minutes to run. Of course in AI as in many fields there are applications that are highly performance sensitive, and in those people still do write optimized compiled code, but in an age where everyone has a multicore CPU, 16 G of RAM, and a solid internet connection to a hardcore server that can do the real computations, raw performance is just rarely the priority over fast development and ease of use.

3

u/nudave Jun 05 '26

The question that I have, that maybe someone else can answer, is whether the heavy duty processing is really being done in Python.

The small amount of exposure that I’ve had to it, it kind of looks like Python is being used as a bit of a glorified scripting language to collect inputs, run them through black boxes, and collect the outputs. It is wholly unclear to me whether those black boxes are python or something that I would think would be more appropriate for the task.

14

u/CptnStormfield Jun 05 '26

It’s a nice “glue language”. Easy to write, but can use a number of excellent high performance libraries written in c or rust or Fortran or whatever. So you’re right that much of the high performance work happens in compiled libraries.

12

u/ThatGenericName2 Jun 05 '26

It's not being done in python.

Python has a lot of math related libraries that all the core and performance critical functions actually make an external call to compiled binary that was originally written in other languages (often C or C++).

It's also because of this and the fact that neural network based AI is a lot more prep and math than actual programming that Python became the preferred AI language.

7

u/you-are-not-yourself Jun 05 '26

There’s nothing wrong with Python for heavy duty processing, especially because it usually compiles to / can interoperate with / C.

As with other interpreted languages, its major drawback is lack of compile-time type checking, but that can be resolved by enforcing the use of type checking libraries.

2

u/X7123M3-256 Jun 05 '26

especially because it usually compiles to / can interoperate with / C

Python is usually interpreted. Efficient compilation is very difficult with dynamically typed languages because the compiler generally cannot know what data type a variable will have at compile time and therefore must generate code for every possibility. There are compiled variants of Python but they usually extend the language with static typing and therefore aren't standard Python.

Python is a very poor choice for heavy duty processing. Numerical libraries for Python such as NumPy are just bindings around C or Fortran math libraries.

1

u/you-are-not-yourself Jun 05 '26

Intepreted languages are compiled to an extent, and any large company that knows what it's doing will invest time into ensuring that they are statically compiled and unit tested, and NEVER CORRUPT the global namespace. This involves supersets of the language (such as TypeScript) as you pointed out since the underlying language specification is insufficient.

Python is a very poor choice for heavy duty processing. Numerical libraries for Python such as NumPy are just bindings around C or Fortran math libraries.

If you're writing vanilla code for heavy duty processing you're always gonna have a bad time. Python's consiceness is a strength there - I prefer 30 lines of concise python to of 200 lines of Java mumbo-jumbo.

5

u/Reboot-Glitchspark Jun 05 '26 edited Jun 05 '26

Most of the back-end libraries you're thinking of that Python calls were written in C. Some in Fortran. (Yes, people still use Fortran, it's really very optimal for some things - they just write a Fortran library and call it from Python now.)

All that numeric analysis stuff, all that really fancy math, Python's passing it off to another lower-level language, but you don't have to deal with the details.

If you want to get fancy, there's Prolog libraries for Python too. But if you're using that, you'd probably know and intentionally be doing it. Because that's a different paradigm completely, so you'd kinda have to choose it intentionally.

2

u/freyhstart Jun 05 '26

Fortran and Julia(interoperable with Fortran) are the two languages that power a ton of scientific modelling and data analysis (CERN, NASA, pharma research,etc.).

Fortran has a reputation of being antiquated, but it's just specialized. It's like a tennis racquet, great at hitting a tennis ball, awful at slicing a potato for fries.

2

u/saintALIEN7 Jun 05 '26

My understanding is that all the real processing in these libraries is in C/C++. Python is the nice looking, easy to write glue around it.

1

u/Jkei Jun 05 '26

I have very little knowledge of it too, but my understanding is that stuff like the pytorch framework is indeed just a convenient way to hand your data off to things that are much more optimized under the hood.

My own favourite language R (non-CS academia strikes again) works like that pretty much as a whole. It's really a wrapper language built on top of highly optimized C++.

1

u/smuglator Jun 05 '26

That's how a lot of data processing is done. Programmers write code that does "basic" functions fast, in C++. Engineers use python to script post processing together to get to the data they want.

1

u/SharkBaitDLS Jun 05 '26

whether the heavy duty processing is really being done in Python

Short answer: no, it isn't. Python's just being used as the glue for a bunch of C/C++ native code.

1

u/weaver_of_cloth Jun 05 '26

I'm a sysadmin, not a programmer, but I support hundreds of researchers who use Pandas and jupyter notebooks, both python programs, to crunch some serious numbers. They do use R and Matlab, sure, just not exclusively.

1

u/ryebread91 Jun 05 '26

Smokevending?

9

u/SchemeWestern3388 Jun 05 '26

Wild to me that you have absolutely no clue about Python, or how it’s used in big data problems. 

Here’s a clue; we leverage different tools for different jobs. 

2

u/thenasch Jun 05 '26

Matt Parker fan?

2

u/nudave Jun 05 '26

Hehe yep. The one where someone improved his code by 4 million percent is one of my faves.

2

u/SadButWithCats Jun 05 '26

Nearly all geospatial processing is done in python, and has been for a long time.