News for hackers. Stuff that matters.
Re:“I'm basically giving myself a permanent vacation from be... by ben509 on Thursday July 12, 2018 @01:10PM (#17516612)
No, the bad decision was treating bytes and strings interchangeably in the first place. 99% of the hardest to fix breakage was due to that, and it was the right call to pay that price all at once.
Re:“I'm basically giving myself a permanent vacation from be... by tialaramex on Thursday July 12, 2018 @02:38PM (#17517386)
I think I mostly agree with you, but it can be unclear to programmers (who are after all the people writing Python code) whether they're dealing with a string, or merely with bytes that happen to look like a string, and this causes hassle.

Until way too recently essentially all Python code couldn't handle basic SSL/TLS certificate validation for Internationalized Domain Names. Once you understand what's going on, this situation is a no brainer: In order to connect to a machine named X, we must have turned X into DNS A-labels that we could look up, and we can treat those as bytes. The certificate must have SAN dnsNames matching its names, and those too are written as A-labels. So we can almost just compare the literal bytes (actually DNS A-labels are "case-insensitive" so we need to handle that, and the asterisk "wild card")

But Python, in its wisdom, defined this API to take a string, and strings, as you observe, aren't bytes. So instead of the above unarguable approach they wasted precious months trying to figure out how best to turn the A-labels from a SAN dnsName into Unicode strings, which isn't even the right problem to solve.

Eventually sanity prevailed: https://bugs.python.org/issue28414

Re:“I'm basically giving myself a permanent vacation from be... by jessaustin on Thursday July 12, 2018 @01:52PM (#17516995)
The API in 2 is not optimal, but they fixed it the wrong way. As you know, some operations make sense with bytes, and some make sense with character strings. The operations that make sense with character strings would also make sense with bytes when an encoding is specified. Therefore, there should just be a way of annotating bytes with a suggested encoding. Then byte-oriented packages (e.g. those that deal with data sent over an interface like a socket or pipe) could simply ignore the issue of encoding. Whole classes of errors would just disappear for many python coders. Other coders, who do care about encodings and non-ASCII characters, would still get those errors but that would be OK because they would know how to fix those errors.

So yes some breaking change was indicated, but the particular change that was made was the wrong one.

Re:“I'm basically giving myself a permanent vacation from be... by ubernostrum on Thursday July 12, 2018 @02:43PM (#17517441)
Then byte-oriented packages (e.g. those that deal with data sent over an interface like a socket or pipe) could simply ignore the issue of encoding.

Long and bitter experience has shown that people who think they can "simply ignore" the "issue" of encoding actually can't. That mindset is mostly a more polite way of saying "people who assume everything is ASCII all the time, or at most an encoding that always has one byte == one character". Those assumptions break sooner or later. I prefer having them break sooner, because I've been the person who had to clean up the mess at an unpleasant time when it was kicked to "later".

Which in turn means Python 3 made the right choice: text is text and bytes are bytes, and you should never ever pretend bytes are text no matter how much you think you'll never run into a case where the assumption fails.

Re:“I'm basically giving myself a permanent vacation from be... by jessaustin on Friday July 13, 2018 @09:38AM (#17522848)
For lots of applications it doesn't matter how many bytes are in a character, because characters don't matter. Even within a particular application, it's common for characters to only matter in a few particular locations. It would still have been a win for python, to make such applications easier to write and maintain.
Re:“I'm basically giving myself a permanent vacation from be... by tialaramex on Thursday July 12, 2018 @02:43PM (#17517444)
Implicitly converting strings into bytes or vice versa means now all your APIs grow an exception "Invalid encoding" / "Can't encode this" / "Can't decode this" / etcetera that you need to deal with.

Making people actually do the conversion has the advantage that when writing their string conversion code they might actually do something with the exception beyond maybe logging it and then pressing on anyway. It also gives you the opportunity to explicitly offer them alternatives like treating everything we can't encode as some sort of replacement character (works well for Unicode, not so much for ASCII), which is way too much to ask of every single function that takes bytes.

Re:“I'm basically giving myself a permanent vacation from be... by jessaustin on Thursday July 12, 2018 @03:42PM (#17517968)
...which is way too much to ask of every single function that takes bytes.

Sorry if I wasn't clear. I meant to suggest that the byte-functions wouldn't know or do anything about encodings. They just work with bytes. It's the other functions, that take the encoding-annotated bytes (or optionally a "pure" unicode type), that would care about encodings.

Re:“I'm basically giving myself a permanent vacation from be... by jrochkind1 on Thursday July 12, 2018 @02:45PM (#17517465)
> The operations that make sense with character strings would also make sense with bytes when an encoding is specified. Therefore, there should just be a way of annotating bytes with a suggested encoding.

That's the ruby solution. I like the ruby API here. When ruby introduced it in 1.9, it did cause similar upgrade pain, since you weren't used to having your strings tagged with an encoding, and suddenly they all kind of need to be if you want to do anything with them as strings-not-bytes.

As someone else noted would be the result, indeed the result was lots of "incompatible encoding" exceptions.

I think ruby actually has a pretty reasonable API here, but several years on, there are still _plenty_ of developers who don't understand it.

Re:“I'm basically giving myself a permanent vacation from be... by jessaustin on Thursday July 12, 2018 @03:54PM (#17518080)
Sure, there are growing pains with any breaking change. Do you think the ruby 1.8 -> 1.9 transition went more smoothly than the python 2.7 -> 3.x... transition?
Re:“I'm basically giving myself a permanent vacation from be... by coldtea on Thursday July 12, 2018 @05:43PM (#17518878)
Sure it did. Barely took a few years, and it also had a large performance boost (whereas 3 initially came with regressions until 3.4 or so).

Plus, basic things like Rails were working from the start.

Re:“I'm basically giving myself a permanent vacation from be... by jrochkind1 on Thursday July 12, 2018 @04:57PM (#17518536)
My impression is that it did, yes.
Re:“I'm basically giving myself a permanent vacation from be... by jrochkind1 on Thursday July 12, 2018 @11:24PM (#17520279)
But on the other hand, Python's overall popularity has grown (mostly on the back of 'data science' I think), while rubies has shrunk, and python is definitely more popular than ruby at the moment... so python's lesser success at that transition didn't actually matter much in the end?
Re:“I'm basically giving myself a permanent vacation from be... by kqr on Friday July 13, 2018 @09:30AM (#17522768)
Encodings are related to storage and transportation -- not business logic. You should not have to deal with encodings inside your application, so forcing programmers to deal with encodings at the point it matters, when text enters and exits the application, is thus sound.

If yoy truly don't care whether or not the text is decodable (which is sometimes the case), then don't read it as a string, read it as a byte array.

You can still have methods that are generic over byte arrays and text, since that is an orthogonal concern.

Re:“I'm basically giving myself a permanent vacation from be... by fgonzag on Thursday July 12, 2018 @03:52PM (#17518069)
Bad decision? UTF was Standarized in 1993, python was first released in 1991. You can't decide to use something that hasn't been invented yet. Back then bytes and string were the same thing. Java did do it right but by 1995 the industry had already seen the problems of differing character sets.
Re:“I'm basically giving myself a permanent vacation from be... by coldtea on Friday July 13, 2018 @08:07AM (#17522175)
>Back then bytes and string were the same thing.

No, they weren't. Impossible as it seems, we had encodings (including multi-byte encodings) for decades before UTF.

Python couldn't use UTF-8 in 1991, but it could very well tag strings with a specific encoding, instead of treating them as a bucket of bytes C-style.

>Java did do it right but by 1995 the industry had already seen the problems of differing character sets.

We had seen the problems of "differing character sets" for decades already (Windows vs DOS version of the same language encodings was a classic example for most users, but the problems go back to EBCDIC and so on).

Java just did a more right thing, but we already have a need for generic string types that can handle multiple encodings and know what they contain and how to convert from one to another.

Re:“I'm basically giving myself a permanent vacation from be... by kqr on Friday July 13, 2018 @02:41AM (#17520956)
I wish I could sufficiently express my frustration for this. It's such a common mistake too. If you design a language with a type for text, and your language has a type called "string" oh God please God let those two be the same thing.

There are so many languages in which the type "string" is not the one to use for strings...

Re:“I'm basically giving myself a permanent vacation from be... by jerf on Thursday July 12, 2018 @03:12PM (#17517687)
"No, the bad decision was treating bytes and strings interchangeably in the first place."

Show me the 1995 software that gets this right, and I'll show you proof that time travel is possible, by simply showing you that software right back again.

Abstractly, yes, it's true. Concretely, though, it's not a particularly valid criticism.

Re:“I'm basically giving myself a permanent vacation from be... by AlexCoventry on Friday July 13, 2018 @10:16PM (#17528411)
> the bad decision was treating bytes and strings interchangeably in the first place

Python preceded unicode, though.