Live data from Hacker News

Code that will break in Python 4

astrofrog.github.io

41–50 of 237 posts

Re: Code that will break in Python 4

#42
As someone that uses Python intermittently it seems like there's still a lot more tutorials, Q&A, and documentation for v2 on the internet than for v3. When searching for info about python it's often difficult to tell if I'm looking at something for v2 or v3, and when I can tell it's usually for v2.

Re: Code that will break in Python 4

#43
post #35
post #25

Often I discover projects that are still in v2, and no words about v3 on their roadmap. Maybe v4 should learn from JavaScript5 and Visual Basic 3-6. Support v2 syntax out of the box using a (slow) shim layer if there is no "use strict" in the first line. If that statement is present, don't load the shim layer and support only v4 syntax (faster). That way old v2 code would still work without any changes.

The syntax changes introduced in python 3 are easy to fix, and most of them are backwards compatible with python 2.7. The whole string/byte dichotomy, however, is a major change that I don't think any shim layer could handle correctly without major bugs, short of defining a whole new string-like class.

The shim layer would have to convert all strings from v2 representation every time to the v4 implementation. Slower, but at least v2 could run unchanged. As we all know certain code won't be touched for whatever reason. It could certainly prevent some from deciding to move off to other languages like Go, Elixir, Node.

Re: Code that will break in Python 4

#48

I don't get it. When Py4 comes in sight they'll fix it probably so `six.PY3` is only True when using a Python3 interpreter and I guess they'll introduce a viariable `six.PY4`.

That is exactly the problem. Code that assumes `not six.PY3` means Python 2 will start breaking.

Re: Code that will break in Python 4

#49

> In this case, no code will get executed on Python 4 at all! Maybe `import six` should trigger ImportError when imported on python 4. Only "eight" or "twelve" should support Python4. :)

Surely it's `import twentyfour`? 2 x 3 = 6 => 2 x 3 x 4 = 24 ;)

LCM(2,3,4) = 12
Post reply on HN