News for hackers. Stuff that matters.
Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Monday January 13, 2020 @01:45PM (#22037269)
> One of the biggest early hurdles in our porting effort was how to overcome the string literals type mismatch between Python 2 and 3. In Python 2, a '' string literal is a sequence of bytes. In Python 3, a '' string literal is a sequence of Unicode code points. These are fundamentally different types. And in Mercurial's code base, most of our string types are binary by design: use of a Unicode based str for representing data is flat out wrong for our use case. We knew that Mercurial would need to eventually switch many string literals from '' to b'' to preserve type compatibility. But doing so would be problematic.

> In the early days of Mercurial's Python 3 port in 2015, Mercurial's project maintainer (Matt Mackall) set a ground rule that the Python 3 port shouldn't overly disrupt others: he wanted the Python 3 port to more or less happen in the background and not require every developer to be aware of Python 3's low-level behavior in order to get work done on the existing Python 2 code base. This may seem like a questionable decision (and I probably disagreed with him to some extent at the time because I was doing Python 3 porting work and the decision constrained this work). But it was the correct decision. Matt knew that it would be years before the Python 3 port was either necessary or resulted in a meaningful return on investment (the value proposition of Python 3 has always been weak to Mercurial because Python 3 doesn't demonstrate a compelling advantage over Python 2 for our use case).

As a general rule, this seems like good practice, but surely b-strings, print_function, etc are a trivial upfront cost, and one that would have to be paid sooner or later anyway?

Re:Mercurial’s journey to and reflections on Python 3 by lacker on Monday January 13, 2020 @02:40PM (#22037800)
It seems like a lot of the cost was when system libraries made different choices than Mercurial would have made. For example, the Python 3 filesystem libraries often used unicode as a wrapper around an underlying bytes interface, and Mercurial really wanted to be able to pass bytes directly to the underlying interface. So it isn't just that they had to update their data types, they also had to adjust code to work with system libraries of slightly different semantics.
Re:Mercurial’s journey to and reflections on Python 3 by wnoise on Monday January 13, 2020 @04:00PM (#22038525)
The python interface usually would take bytes, and if it did would also return bytes. But there were a lot of things that didn't take arguments, so always returned Unicode strings. Instead of e.g. getcwd(), you would have to use getcwdb(). Which naturally didn't have an equivalent in python 2 though they did add the complementary getcwdu() (which one should basically never use).
Re:Mercurial’s journey to and reflections on Python 3 by novok on Monday January 13, 2020 @02:29PM (#22037695)
Having done a py2 to py3 migration and ran into the same issues, these wouldn't of been that big of a deal IF python had static typing from the get go.

The static compiler would notice all the breaking type changes at compile time and you can systematically fix all of them at once. You wouldn't miss one or two and have to run your unit testing suite to exercise the type system underneath.

I really believe big breaking changes like this in a language causing migration stagnation is a property of dynamically typed languages. With other statically typed languages like swift or rust, it happened quite frequently but wasn't as big of a deal in practice.

Re:Mercurial’s journey to and reflections on Python 3 by TylerE on Monday January 13, 2020 @06:15PM (#22039834)
Python with static typing wouldn't be python. It wouldn't even be python-adjacent.
Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Monday January 13, 2020 @06:21PM (#22039883)
Python has had static types for years. https://www.python.org/dev/peps/pep-0484/
Re:Mercurial’s journey to and reflections on Python 3 by TylerE on Monday January 13, 2020 @07:02PM (#22040215)
Yes, because optional annotations are totally the same thing as changing the languages basic functionality.
Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Monday January 13, 2020 @07:43PM (#22040560)
Oof, that’s quite a take. Static type checkers by definition don’t change the language’s functionality; they merely check the types.
Re:Mercurial’s journey to and reflections on Python 3 by TylerE on Tuesday January 14, 2020 @12:33AM (#22042139)
Static typing is ceremony. That is anti-Python.

If you want Java, write Java. Don't try to make Python Java.

Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Tuesday January 14, 2020 @09:35AM (#22045036)
It’s literally Python, and if you’re writing sane/correct Python, you should hardly notice (things will work a little better, documentation will be more complete and actually accurate, etc). You can even do many of the same bizarre things that shitty Python programmers do without static typing, such as return differently types data based on the value of an input parameter. Someone passes in the string “asdf” so we’ll return an int, but if they pass “xyzfoo” we return a datetime. Next thing you know you’ve built matplotlib.
Re:Mercurial’s journey to and reflections on Python 3 by kingemer on Monday January 13, 2020 @02:08PM (#22037494)
It sounds like the cost was non trivial for them, partially because they weren’t allowed to break things for python2, or even disrupt the efforts of those using it.

The language wasn’t ready for the transition, but it feels like it may have been even harder on them because of the requirements imposed on their project.

Re:Mercurial’s journey to and reflections on Python 3 by kingemer on Monday January 13, 2020 @02:11PM (#22037533)
Considering how much opposition there is in moving to python3, has there been any significant effort in the community keeping python2 alive?
Re:Mercurial’s journey to and reflections on Python 3 by acdha on Monday January 13, 2020 @02:26PM (#22037668)
Most of what opposition there is comes from people with projects which are some combination of under-staffed, poorly tested, or with a marginal approach to scheduling necessary maintenance work. That is not a great place to expect to find reliable maintenance contributions.

Where you are more likely to find this is from the major Linux vendors: e.g. Red Hat is committed to support it through 2024 and I would expect that they won't be alone in offering paid support for remaining users.

Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Monday January 13, 2020 @02:52PM (#22037928)
I'm actually (pleasantly) surprised that someone like Google (or a league of someones like Google) who have deep pockets and so much Python 2 that it's cheaper to maintain Python 2 than it is to port to Python 3. Perhaps they (correctly) were concerned about the ecosystem moving on toward Python 3, leaving them behind?
Re:Mercurial’s journey to and reflections on Python 3 by weberc2 on Monday January 13, 2020 @02:47PM (#22037876)
Right, they could have paid a nontrivial cost (asking devs to use b-strings, print_function, etc) but didn't by fiat, choosing instead to pay a greater cost during the migration in addition to the nontrivial cost. My comment expresses skepticism about that decision.