- speeds matters of that level matters only for a limited number of use cases. Most programming use cases are fine with python speed. They were fine, in fact, with it 20 years ago, before we got that hardware speed.
- people are starting to complain about speed in python only because of all the data science going up. Suddenly here speed matters. Before, you had to get to google level of infra to find use cases where python was too slow.
- dev are expensive. Hardware is cheap. If you have a slow website, paying $200 dollar more on your server is not a big deal. But taking 3 more month dev that features with your $300k pro is another thing entirely.
Now of course, you gotta remember that installing something is usually more than copying the code, and there is nothing to help you with that, in any language.
Welcome to the world of deployment, which is why things like ansible and docker exist.
Python already does so much for you, and provides so much tooling to do even more, it's hard to write bad code if your daily job is to be a coder.
The iterator protocol means you rarely get off by one errors, context managers and GC deals with resource handling, the GIL, for all its faults, helps a lot of concurrency errors...
Now, add a good IDE, and syntax errors, names errors and attribute errors go away. Play a little in the REPL, and use cases become more obvious, behaviors more clear.
Want more security? You can add type hints and unit tests (which are incredibly easy to write, thanks to pytest).
Even without all that, the size of the ecosystem means you won't write most of the code anyway, and less code, means less potential for mistakes. Adds to that the language bare bone syntax, and you really has something that actively helps with writing good code.
Not to say you can't write bad code in Python, but unless you are not a professional dev (in that case, you can write bad code in any lang), you have a lot to help you there.
Not to mention facebook leaders don't care, they already made billions by misbehaving without any consequence. Even if the story did end there, it's 100% win for them.
This is the lesson of our generation: makes money by delegating the consequences to society. Nothing will happen to you. In fact, in 20 years, you could buy the service of some PR firm, and they will even make you a hero in the eyes of the public eventually.
I mean, they abuse the system like dictators "abuse" guns to kill people.
If you have a company selling a weapon, it's pretty obvious it's going to be used to harm. That's by design.
And just like we were never able to prevent the guns to arrive in the hand of the wrong people, or make sure people using guns respect any kind of rules, why would we expect NSO clients to be well filtered and behaved?
If you are a 40 year old, inactive person, try defending yourself against a knife or a club, especially against a younger person who has had experience using it.
But that is what I meant, this StopIteration would not be affected by the zero cost optimization. The zero cost optimization is about compiled Python bytecode and the VM interpreter. The StopIteration is handled internally by CPython (not via Python bytecode).
For example, consider this function:
def foo():
for i in range(3):
print(i)
There is no try-except in this code, and neither in its bytecode. So this is not affected by the zero cost optimization from the linked issue.
The iteration logic is inside the `FOR_ITER` op. And that is purely handled inside CPython.
Also, this is again what I meant: In user code, you rarely would use custom exceptions for control flow. Please show me any example where you have seen otherwise.
So, again, what I wrote: I'm very confident that for most user code, the code path under `except ...:` is only rarely executed. Please show me any big Python project where this would not be the case. I doubt that there is any.
> The for loop in python is a try/except catching StopIteration in a trench coat.
That's...horrifying, both from a computational efficiency perspective (due to the overhead of exceptions) and from a "beauty" perspective (exceptions are supposed to be exceptional, darn it!). Why is it implemented this way? Why not just use a normal loop and check a return value from the iterator?
(It's certainly not unanimous. Guido himself is on the record as saying EAFP isn't better than LBYL, but in most of the Python I've cruised through these last umpteen years [that wasn't some other language written in Python], I've certainly seen an overall preference for EAFP. Naturally YMMV.)
I think that implies that either "exceptions" are misnamed in Python (as in every other language with that name, they're meant to be exactly that - exceptional - so whatever Python calls "exceptions" isn't the same as in other languages), or that that particular idiom is wrong, and needs to be rethought.
> Why not just use a normal loop and check a return value from the iterator?
Because an iterator needs to be able to return any python value, and if you did that, there would be at least one python value that an iterator could not actually return.
Unless you required the iterator to wrap real return values in a container (basically, an optional/maybe monad) but then you have unwrapping overhead on every real return value, which is worse.
Couldn't the runtime just allocate a specific Python object representing the case where the iterator is complete? Make that object implementation-specific, hide it as best as you can, write documentation stating that users should not use this value directly, and if they do - they voided the warranty, and should expect evil to befall them. (ultimately, you can't prevent the user from doing really dumb things e.g. editing the Python binary directly)
You do that with two or more of the protocols that Python has that use return values for return values ans exceptions for flow control signals and...you make it a lot harder to work with them, especially in conjunction.
Can you give an example of this? I can't think of any myself - generators also raise a StopIteration exception, for instance, so they could use the same value.
> they have created a system of incentives that are inexorably leading to harmful outcomes
If the people inside are "smart, thoughtful, kind, well-intentioned people", they would have tried to work around the incentive, influence them, denounce them, or quit.
It rarely happened. Most of the time, the just take the money, and goes with the flow.
A long time ago, I worked in a startup full of smart, thoughtful, kind, well-intentioned people. Of course, there was also a CEO who was a ruthless manipulator and managed to make everyone believe that they were working for the greater good. In truth, in the course of lining his pockets, he was in the process of destroying several employees and former employees.
Getting past the illusion was hard.
Taking a stand against said CEO while nobody else was aware of the problem? Really, really hard.
Now, instead of a few dozen employees, Facebook has tens of thousands. I assume that all of them are subject to permanent propaganda, as in many tech companies, and that the semi-official word is that they are being misunderstood by the rest of the world, because of course they are doing the right thing but the problem is harder than people think (well, that last part is true, at least). I suspect that it's even harder to go against the flow.
It's a good insight for any transformation really, including change in code: look at what's in common between the desired outcome and the current situation to have an idea how how much work to do.
- speeds matters of that level matters only for a limited number of use cases. Most programming use cases are fine with python speed. They were fine, in fact, with it 20 years ago, before we got that hardware speed.
- people are starting to complain about speed in python only because of all the data science going up. Suddenly here speed matters. Before, you had to get to google level of infra to find use cases where python was too slow.
- dev are expensive. Hardware is cheap. If you have a slow website, paying $200 dollar more on your server is not a big deal. But taking 3 more month dev that features with your $300k pro is another thing entirely.