On Tue, Feb 25, 2020 at 5:52 AM Alex Hall <alex.mojaki@gmail.com> wrote:
Of course consistency is valuable. I am asking how it is automatically more valuable than "better or worse", which isn't an idea that makes sense to me. Consistency isn't axiomatically valuable, it's valuable for reasons such as what you've explained which ultimately boil down to what's better or worse. Those reasons can be outweighed by other considerations. Consistency is not *infinitely* valuable.
Thing is, "better or worse" could mean an extremely marginal difference, whereas "consistent or inconsistent" is a fairly sharp distinction. So it's a question of HOW MUCH worse it's okay to be, to avoid being inconsistent. And actually it's okay to be quite a lot worse in a vacuum, if it's better for consistency.
But let's assume they have, and they're curious why they got a warning. Or more likely, let's assume that they don't immediately figure out what to do from the warning message. The obvious next step is to search for the message online. This is a specific warning regarding iterating over strings, so the results will specifically be about this topic. Through Google's algorithm and Stack Overflow's votes, they will probably land on an explanation that is widely regarded as one of the best online, so probably better than what I'm about to offer.
Remember that this proposal is not for a new feature, but for a CHANGE to existing behaviour. So there'll be lots of code out there that happily iterates over strings. Also remember that iterating does not only mean "for x in y", but can be seen in various other forms: a, b, c = "foo" list("foo") dict.fromkeys("spam", "ham") Getting a warning from one of these lines of code will not necessarily explain the problem nor the correct solution.
So in a nutshell:
1. I think that users being confused about this inconsistency is not going to harm them as much as you seem to be claiming. 2. I think that users will learn to understand the reasoning behind inconsistency from practical experience, more than any explanation.
Even when there is a wealth of code out there that will become broken by this change? It's creating inconsistency across data types within a single Python version AND creating temporal inconsistency across Python versions with a single operation.
By contrast, the examples you've given are definitely harmful and difficult to understand. I've been personally baffled by the first example. But the real problem with them is deeper than inconsistency. The problem is that they are surprising, confusing, and difficult to debug. Which is exactly the kind of bug that the proposed warning is meant to defend against, and definitely not the kind of problem that will be caused by seeing said warning and contemplating inconsistencies in the data model.
The JS one gets even more fun when you consider that arrow functions don't behave that way. Believe me, these kinds of inconsistencies DO crop up, and they DO impact my day-to-day life (not the PHP one fortunately, I left that abomination behind years ago - but the JS function issue comes up at least every few weeks). Don't underestimate the cost of this kind of flaw, where making an insignificant change suddenly breaks the code. ChrisA