But its syntactically weak? Python itself is slow? pip is awful (although uv is pretty good). Sometimes I am forced to write python because the packages I need are written for it but I always hate it.
But its syntactically weak? Python itself is slow? pip is awful (although uv is pretty good). Sometimes I am forced to write python because the packages I need are written for it but I always hate it.
This is revisionism.
When I was in school, that's what people would say about C/C++/Java.
People like me switched to Python well before it became common to teach it at school. Lots of great libraries were written in it before then as well. I mean, it's really easy to write a library in it than it was in most other languages.
It was picked for teaching in schools because it was a decent language, and was already widespread. It's much more useful to teach Python to an average engineering student than C/C++/Java.
It became popular because it was easy to learn, and a lot nicer to use than the other big scripting language: Perl. When I was in grad school, I would routinely find non-engineers and non-programmers using it for their work, as well as writing libraries for their peers. There is no way they would have done that in any of the prevailing languages of the time - many of them learned to program while in grad school. It became quite popular amongst linguists. Then NumPy/SciPy became a popular alternative to MATLAB, and once again my peers, who would never write C++ to do their work, were suddenly getting matching speed by using Python. That's how it ended up being the language for ML.
So no - the fact that it's taught in schools is not the reason it's used today.
Sure, and this is my argument. It is easy to start out with, which makes it appealing to academics without a CS background. But is this a good thing? Because then these academics without a CS background write monstrous, poorly optimized scripts compounded by a slow language, then use drastically more compute to run their science, and then at the end publish their paper and the scripts they used are very hard to adapt to further research because very rarely are they structured as modules.
Just because it is easy to write doesn't mean it is the most appropriate for science. It is not commonly acceptable to publish papers without a standardized format and other conventions. Students put in work to learn how to do it properly. The same should be true for code.
For many of them, the alternative is that they simply wouldn't have done the science, and would have focused on research that didn't need computation. Or they'd use some expensive, proprietary tool.
Prior to Python becoming popular among them (circa 2005-2007), plenty of good, fast, whatever-metric-you-want languages existed. These academics were not using them.
Python is really what enabled the work to be done.
Is it? I've never actually seen or heard exactly how Python became popular with survey data at many institutions. If it exists, I'd like to read it sometime.
Most languages got popular due to a specific project or product getting popular or a specific company marketing them.
I've heard it was UNIX/C, Browser/JavaScript, Sun/Java, Microsoft/many (esp C#), Google/Go, Apple/Objective-C, Apple/Swift, Ruby/Rails, and so on. I've heard variations of C++ being like this but also useful building on C ecosystem.
Some were really great at a specific thing they made easy. PHP might be like that. I don't have its history, though. Flash was definitely like that.
So, did Python have a killer app or library that caused it to take off industrially? Or did that not matter? You mentioned NumPy/SciPy in academia.
This is a bold assertion, and IMO, false.
What was the killer product/company marketing that made Perl popular?
> So, did Python have a killer app or library that caused it to take off industrially? Or did that not matter? You mentioned NumPy/SciPy in academia.
It really didn't. It was already popular before, say, Django came around. Yes, NumPy/SciPy are kind of the reason ML is on Python, but the reality is people in academia chose NumPy/SciPy over MATLAB because it allowed them to use Python libraries in their code, which MATLAB could not. In other words, the academics chose to use NumPy/SciPy because they already were into Python.
For many, Python was just a much nicer alternative to Perl, and it was one of the main "batteries included" languages. That's why it became popular. Keep in mind that Python did not become popular quickly. It came out in 1990 and took about a decade to become somewhat popular.
The only other thing I can think of is this essay by Eric Raymond in 2000:
https://www.linuxjournal.com/article/3882
"My second came a couple of hours into the project, when I noticed (allowing for pauses needed to look up new features in Programming Python) I was generating working code nearly as fast as I could type. When I realized this, I was quite startled.
This was my first clue that, in Python, I was actually dealing with an exceptionally good design. Most languages have so much friction and awkwardness built into their design that you learn most of their feature set long before your misstep rate drops anywhere near zero. Python was the first general-purpose language I'd ever used that reversed this process.
...
I wrote a working, usable fetchmailconf, with GUI, in six working days, of which perhaps the equivalent of two days were spent learning Python itself. This reflects another useful property of the language: it is compact--you can hold its entire feature set (and at least a concept index of its libraries) in your head. C is a famously compact language. Perl is notoriously not; one of the things the notion “There's more than one way to do it!” costs Perl is the possibility of compactness.
...
To say I was astonished would have been positively wallowing in understatement. It's remarkable enough when implementations of simple techniques work exactly as expected the first time; but my first metaclass hack in a new language, six days from a cold standing start? Even if we stipulate that I am a fairly talented hacker, this is an amazing testament to Python's clarity and elegance of design.
There was simply no way I could have pulled off a coup like this in Perl, even with my vastly greater experience level in that language. It was at this point I realized I was probably leaving Perl behind.
...
So the real punchline of the story is this: weeks and months after writing fetchmailconf, I could still read the fetchmailconf code and grok what it was doing without serious mental effort. And the true reason I no longer write Perl for anything but tiny projects is that was never true when I was writing large masses of Perl code."
I don't like Python for "applications" as much. I was at a place almost 10 years ago now that had Python "microservices" running in Kubernetes. managing performance and dependencies for Python in production is just unnecessarily futile compared to something like Go that's also very accessible syntactically.
AFAIK, it's the preferred language for lots of leetcode, e.g. Advent of Code. The practical expressivity and speed of dev is strong.
It drives me crazy how everything just... blocks. Parallelization is a disaster.
I won't comment much on indentation. All the string formatting syntaxes is crazy. Private names managed by `_`. The type system still mostly sucks. Ect ect.
In my experience it is alright to write short scripts but complexity very quickly balloons and python projects are very often unwieldy.
I would write a script in python, but only if I was positive I would never need to run or edit it again. Which is very rarely the case.
I too would prefer let. But the number of times what you mentioned has bitten me in almost 20 years of programming Python can be counted on in one hand. And these days, just use the "rename" feature in your IDE!
This is an extraordinarly common feature among scripting languages. In fact, JS is really the odd duck out.
Shell, Ruby, Lua, Perl, R, AWK, etc
> I rename the variable but forget to change it where it is updated.
Type checkers will catch this. (And IDEs will help.)
You don't have to use type checking of course, though it sounds like you like to.
> It drives me crazy how everything just... blocks.
There are comparatively few languages that primarily rely on cooperative multi-threading.
> All the string formatting syntaxes is crazy.
f"Hi my name is {name}"
---FWIW, you just don't like most scripting languages.
Which is fine, but it goes far beyond Python.
Python, Perl, Ruby, PHP, Lua, Tcl
Slow is relative. You need to account for the time to write as well, and amortize over the number of times the code is run. For code that is run once, writing time dominates. Writing a Java equivalent of half of the things you can do in Python would be a nightmare.
where "run once" in the sense you describe is really the case has been rare for me. Often these one off scripts need to process data, which involves a loop, and all of the sudden, even if the script is only executed once, it must loop a million times and all of the sudden it is actually really slow and then I must go back and either beat the program into shape (time consuming) or let it execute over days. A third option is rewriting in a different language, and when I choose to do a 1:1 rewrite the time is often comparable to optimizing python, and the code runs faster than even the optimized python would've. Plus, these "one off" scripts often do get rerun, e.g. if more data is acquired.
Java is a sort of selective example. I find JavaScript similarly fast to write and it runs much faster.
The vast majority of my Python code is for data exploration and preprocessing which are usually one-offs or need to be run only a couple of times. Or maybe it’s a nightly job that takes 5 minutes instead of 30 seconds in another language, but it doesn’t matter because it’s not user facing.
Actual Python execution time very rarely comes into play. If it does and it’s a problem, I will create a pyo3 rust binding.
Correct. Relative to the languages I prefer, Python is slow
Python encourages people to write long scripts and large projects comprised of many scripts
Are these "run once" programs
Python is one of the least energy efficient languages
There seems to be an enormous amount of effort spent on trying to make Python faster. To me, this implies it is slow or, at least, not fast enough, but others may see things differently. The language has a devoted following, that's for sure
For me, the startup time makes Python unusable
JavaScript has gotten drastically better, especially since ES6. The lack of venvs alone is such a breath of fresh air. The baseline typing sucks more than python, but typescript is so much better. It still suffers from legacy but the world has mostly moved on and I don't see beginners learning legacy stuff much anymore. Modern javascript is amazing. I do my work in Elysia, Kysely (holy crap the python database situation is awful) and everything just works and catches tons of errors.