Code that will break in Python 4
astrofrog.github.io
astrofrog.github.io
This is e.g. how the (roughly analogous) split between C and C++ is handled, and it works fine for the most part. No bizarre polyglot code games.
Edit: Just to be clear, C++ is not a superset of C: http://stackoverflow.com/a/1201840/270610
Because that would make the interpreter a whole lot more complicated. A lot of technical debt was cleared with the 2-3 transition, adding it back in defeats the point.
C/C++ is different, C++ is a superset of C. That makes things a lot easier.
Edit: Ok, C++ is not a superset, common misconception.
http://stackoverflow.com/a/1201840/111426
However, it's close enough that I generally agree with your point.
This is entirely incorrect, but I'll give you a break since it is a common misconception. C and C++ are truly two different languages. C is not 100% compatible with C++.
No it isn't.
Also major issues people have with migration is unicode. In respect of unicode, majority of the code is simply broken and fails to work on Python 3 because Python 3 is more strict about it.
In Python 2 you store text and binary data as bytes (no distinction, there is unicode type but it's more hassle to use it and frankly almost no one does use it) while in Python 3 text and binary data are two distinct types.
So if you have code in Python 2 and you did not distinguish what is text and what is binary now you have to go through your entire code and identify all those parts, this is especially hard since Python is dynamically typed language and you don't have type checker to help you with that.
This is also why it is much easier to write Python 3 code and make it run on Python 2 as well than the other way around.
As for having interpreter compatibility layer. First python does not care about extension you use, and unlike some languages it actually allows you to install multiple versions at the same time without conflicts (checked 2.4 all the way to 3.5). You can easily control which version you want to use by shabang, for example:
#! /usr/bin/env python2
#! /usr/bin/env python3
#! /usr/bin/env python3.5Shebang doesn't work on a per-module basis, which is what I am advocating. If there were a way to specify versions at that granularity, there would be no need for 2/3 polyglot tricks.
I guess I'm incredibly lucky or you're incredibly unlucky, because I did not run into a library that would only run on Python 2. Ok, I did run into some, but those were no longer maintained and frankly I would not use them even on Python 2.
Assuming python points to python2 will also break stuff, though, there are more bleeding-edge OS's where python points to python3 and has done so for years (e.g. ArchLinux).
Sadly concurrent running in the same interpreter won't work because Python 3 has different types for strings (unicode only) and a bytes type, while Python 2 has a str type (pretty much like bytes but can also be treated as a string) and a separate unicode type. Python 2 had code that tried to do the right thing automagically with str, such as automatic promotion to unicode where it looks like you really meant a string and that is what is needed. Automatic promotion can fail, be unexpected, is hard to test and numerous other issues. That is why Python 3 was needed and why it needed to be incompatible. To have Python 2 and 3 code interoperate in the same interpreter would require another layer of automatic promotion/demotion and heuristics when data goes between the two.
C++ was explicitly defined to be a superset of C so it doesn't have these kind of issues. The analogous situation would be if C didn't distinguish between long and pointer types, and C++ did. You'd need rules for how to convert between the two worlds, trying to combine or disambiguate the types depending on which way types are going. It would be a mess.
C++ is not a superset of C: http://stackoverflow.com/a/1201840/270610
C and C++ have a similar issue with strings. C code uses NUL-terminated char arrays, while C++ generally uses std::string. If you want to interface the two, you need glue code (written in C++).
Surely Python 3 can work the same way: to share strings between a Python 2 and Python 3 module, you need to convert them using glue code written in Python 3. Sure it's messy, but writing polyglot code is messier.
I don't know that it would be impossible to make that all work, but I wouldn't assume that it is.
Function pointers are one scary area. I don't know if C++11/C++14 decided to fix this yet. Most people relied on undefined behavior to make this work.
Source: The Design and Evolution of C++, by Bjarne Stroustrup. (I don't know which printing I have.) Page 120, Section 4.5 "No gratuitous incompatibilities with C". It explains my original claim, and also why it couldn't be 100% compatible due to some other C++ desirables (eg better type safety). Partial quote:
"C++ doesn't aim at 100% compatibility with C because that would have compromised the aims of type safety and support for design. However, where these aims are not interfered with incompatibilities are avoided - even at the cost of inelegance. In most cases, C incompatibilities have been accepted only when a C rule left a gaping hole in the type system."
Then Python 3 code could use every unmodified Python 2 library (albeit potentially requiring the former to do some messy conversions between str and bytes when making calls), including the long tail of legacy libraries that will never be upgraded. Meanwhile, once the issues in the first Python 3 release or two were straightened out, there would be very little reason to use the Python 2 interpreter, since the Python 3 one would be a drop-in replacement; so migration to the latter would be relatively swift, and it wouldn't be too much of a burden to ask someone to upgrade as a prerequisite to using your code. So there would be very little reason to write new Python code in the Python 2 dialect (unless you really really hate making print a function :), and existing code could be migrated one file at a time. Including popular libraries that wanted to maintain backwards compatibility with Python 2 programs - they would have to add compatibility checks similar to the standard library, but could otherwise go full Python 3, rather than having to use the awkward intersection of language semantics and compatibility libraries currently required.
With the transition so much smoother overall, native Python 3 code would probably take over relatively quickly. (Maybe it would have even been feasible to remove the Python 2 compatibility layer eventually, though probably not.) Whereas in reality, today, over 7 years later, Python 2 is still more popular than Python 3 [1].
Nope, not quite. Python 2 is named python2 and python 3 is named python3, on every system I am aware of. 'python' is ambiguous and can be linked to either [1]. I know at least on Arch Linux, python links to python3, and I have run into a handful of scripts that break by assuming python is always linked to python2.
The interpreter is too messy for that and the transition to Python 3 was not considered well enough. There is no hope on that front. Even if you solve everything else, the C ABI will still be broken.
In all reality, Python 2 and Python 3 are completely differently languages at this point. Communities/companies/projects that have adopted Python 2 do not care about anything that Python 3 gives them. Take for instance Flask - to maintain compatibility with the WSGI spec they have to maintain Python 2 compatibility indefinitely. Less than 30% of all software is compatible with Py3 and any new software releases are built on top of Python 2 - yes I'm looking at Tensorflow.
I'm very doubtful that Python Foundation is going to drop support by 2020. Quite simply - a highly funded Python company (like anaconda) can create a fork.
The only way this situation can be fixed is Python 4 with co-existence of Python 3 and Python 2 functions.
> the Python philosophy around one-true-way to do things
I've always thought to be a total joke. There's been like 5 different modules each for string interpolation, subprocess management, and argument parsing. Heck, I thought I was on top of which was in vogue and apparently just two weeks ago there's a new "one true way" to do string interpolation.
> Barry Warsaw, one of the core Python developers, once said that it frustrated him that "The Zen of Python" (PEP 20) is used as a style guide for Python code, since it was originally written as a poem about Python's internal design. [0]
I did a quick search for a little more background but didn't find anything. I'd be curious to hear more.
[0]: https://github.com/amontalenti/elements-of-python-style#a-li...
Almost all the lines on the Zen of Python are inversion of the Perl guidelines. Some with the exact same phrasing, just with the antonyms of the original.
Check the very first issue that was reported: https://github.com/tensorflow/tensorflow/issues/1
You mention C++ as though it worked out great, but C++ is still full of sharp edges and features that interact weirdly with its C legacy, and it has never completely replaced C (especially for libraries). And that's despite having a few advantages that made it possible in the first place, like having a completely different stdlib built on top of the C stdlib, and producing machine code rather than compiling for a VM on the fly.
Microsoft thought there were too many broken version checks in the wild, so decided to hobble the version check function as a fix. I can understand why they did it.
[0] https://www.reddit.com/r/technology/comments/2hwlrk/new_wind...
IMHO, the most probable reason was marketing (OS X).
from __future__ import __all__Somehow all of those libraries are still smaller than my slack desktop app.
https://en.wikipedia.org/wiki/List_of_burn_centers_in_the_Un...
Of course, this opens the opportunity for two other compatibility libraries. "twelve" will be for supporting Python 3 and 4 and "twentyfour" will support Python 2, 3, and 4 at once (I hope nobody will seriously consider a library called "eight").
import fortytwohttp://www.everything2.com/title/what+do+you+get+if+you+mult...
I personally doubt the author's statement: "six will be long dead and forgotten by the time Python 4 rolls around."
You're talking about the Python development team, by the way.
Of course they're pedants who want to clean things up. That's why we have Python.
print("HI") # yaaaah, order out of chaos
Unconvincing.
The big change was string/byte-array typing, which was a mess in Python 2 and was cleaned up in Python 3. That's one of those things that, when changed, inherently breaks old code in ways that, like wizards, are subtle and quick to anger.
Also changing lots of sequence functions like range() to return iterators instead of lists, but those are mostly pure performance wins that don't break compatibility except for some very specific use cases.
And made worse in some cases (e.g. http://legacy.python.org/dev/peps/pep-0461/). Even aside from that, I would argue that the benefits of cleaning up Unicode didn't come close to the cost of breaking everyone's code and fragmenting the language for 7+ years.
print >>sys.stderr, "Hi", # horror
print("Hi", file=sys.stderr, end="") # order
But the important change was Unicode.Maybe `import six` should trigger ImportError when imported on python 4. Only "eight" or "twelve" should support Python4. :)
2 x 3 = 6 => 2 x 3 x 4 = 24
;)
There were faster languages (and probably more 'parallel-aware' languages - it's not an area I'm very knowledgeable about) before Python but that wasn't the reason it took off. It's fairly unlikely to be the reason it dies off either.
Python remains one of the most humane languages out there and that's a quality that is much more intangible and hard to replicate.
Glancing at the code samples, I don't hate it. It looks rather pleasant.
I can't fathom
Doesn't compute.
You can't say you don't know anything about Python4 and immediately follow up with suggestions on how to program for it.
And if you really want to be consistent, at least:
if (python2):
// python 2
else if (python3):
// python 3
else:
raise "I have no idea what I'm doing"
At any rate, given the time lapse between Python releases and how catastrophic version migrations have been so far, it's safe to say that by the time Python 4 comes out (if ever), we will all have long retired from development.Not that there aren't a lot of things _right_ with python...
But long before we switch to python 4, we should stop trying to be backwards compatible with python 2.
I think maybe the Python 2/3 split was a huge performance piece on how NOT to evolve a language, but we just copied Perl 6.
Do you think a stop the world, forced upgrade is something that should be done in the future? Was it avoidable?
I had to write a shared library to override the call and inject that into the CrashPlan process so it'd be happy. Fun times.
Historical note: FreeBSD1 was rebased after the AT&T lawsuit on top of the unencumbered Berkeley release as FreeBSD2. To run FreeBSD1, you probably still need an AT&T UNIX license.
SunOS 4.1.4 was retroactively renamed Solaris 1.1.2.
SunOS 5.6 was Solaris 2.6, but
SunOS 5.7 was Solaris 7.
To Sun's eternal credit, they were smart about keeping the internal versioning and the marketing versioning separate.Even to this day, so far, Oracle hasn't messed with "SunOS".
Never allow developers to read the version number. Instead have a function where they pass in the version number and get a boolean about whether or not it's supported.
It's really the only way to avoid code problems like this.
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms7...
This is a very real scenario when you consider the application is explorer.exe and the plugin is any software that installs custom context menu actions.
I just wish software would take versions seriously. Please. For my sanity.
Don't get me wrong, I do understand your frustration. But "previous increments actually meant something, so when it now no longer does" is just totally incorrect. Previous increments were an attempt at bundling together a series of unrelated changes into a 'thing'. What that 'thing' is varied wildly between organizations and products. Semantic version increments are breaking changes, pure and simple.
For Linux, 2.0 was just SMP support. In defense of Linux, there has never been a backwards breaking major version increment, suits are just paranoid about the number going up randomly. They want it to have meaning, even when it does not.
For Python, 2.0 was not breaking, but 3.0 was. Now that major version has breaking significance in accordance with semver, business interests will treat it like that and make a big deal out of a 4.0, even if it is not breaking. I know this because I deal with clients paranoid about Linux 4.0 all the time, despite insistence Linux never breaks backwards compatibility.
Fundamentally neither project is adhering to semver and are using arbitrary version systems, but if you are going to do that, it would be so much nicer if they would use a two number version - major-patch - rather than having a dead major version that is meaningless. Honestly, in programming languages, Python 3 should have legitimately been a language fork like C++ is to C rather than a version increment (like Obj C is to C) - programming languages are making a bad habit of making breaking changes in a language, and while its understandable that the developers no longer want to maintain the old standard, its deceptive to call the version increment the same language since the semantics change when you make major breaking changes like that.
Whether that was a smart decision is another discussion. But to call them both Python 2 would be moronic.
couldn't agree more. Yet all the evidence is that they're still using 3.x as their personal little hobby playground. Exhibit A: type annotations. Just because others are doing it. Nobody is asking for this. Even the PEP took ages to approve because even the yes-men had their doubts. Exhibit B: re-invent green threads. There are 15 solutions already.
Where is GPU? Where is multicore? Where is speed?
Where is the leadership?
> My current expectation is that Python 4.0 will merely be "the release that comes after Python 3.9". That's it. No profound changes to the language, no major backwards compatibility breaks - going from Python 3.9 to 4.0 should be as uneventful as going from Python 3.3 to 3.4 (or from 2.6 to 2.7). I even expect the stable Application Binary Interface (as first defined in PEP 384) to be preserved across the boundary.
http://www.curiousefficiency.org/posts/2014/08/python-4000.h... (which was linked by Guido from his Twitter).
It probably goes back further than that, and it was probably one of those "everybody knows..." kind of things, but it definitely didn't start to be a widely-known definition a measly seven years ago.
The main thing that helped make SemVer the default assumption was package managers that baked it into the dependency resolution, as until then a project's versioning scheme really didn't matter very much to the users of the project as long as it wasn't completely incomprehensible.
Everyone understands what 3.100 means, too.
I expect there probably will be at least some breaking changes in 4.0 or at least major new additions to warrant the major version bump, but I think they want to avoid anything that makes migrating code/libraries anything more than trivial for the majority of users. For 2->3 stuff like print as a function was straightforward, but other stuff like lazy range() or the Unicode strings would actually require people to make significant changes, which stagnated migration.
Please don't. From the site guidelines: When disagreeing, please reply to the argument instead of calling names. E.g. "That is idiotic; 1 + 1 is 2, not 3" can be shortened to "1 + 1 is 2, not 3."
http://www.curiousefficiency.org/posts/2014/08/python-4000.h...
Would be nice if it was simply 3.10 not 4.0, as there's much discussion on that too.
It will become pithon.
What? If that's the idea, don't be stupid and just call it Python 3.10 then.
Otherwise, won't we risk a completely unnecessary major versioning problem as outlined in this very article??
Sometimes it feels like the Python team wants to change the major version number only to teach the development community a lesson about coding libraries right, not because they have to. This kind of masochistic idea of deciding version numbers, if it's there, needs to go since this lesson will never be learnt by each and everyone due to the immense size of the community. And if there is a support issue in some libraries, the ripple effect can and will affect other projects as well.
import ai
ai.run('This script <describe in natural language what you'd like this script to do>.')ie once future syntax develops, start using it immediately using a transpiler, and have builds that target as many versions as you care to support.
Sorry, I couldn't keep a straight face for that one.
Obviously you don't know if (modern code) is Py4 compatible, since we don't know what py4 is, but while the py3 code MIGHT be runnable under py4, the py2 code is ALMOST CERTAINLY not going to run under py4.
So instead, make the check for PY2 code:
If Py2 do (old code), else do (modern code).
That MIGHT break under Py4, if modern code isn't future code, but also MIGHT work, whereas the other version WOULD break under Py4.
Same story if you're using sys.version[] rather than six.
Will there be a 3.10 or go to 4.0 after 3.9, per one of his core developers?[1] It's hard to tell with Python's leadership (no intentional mockery of the term leadership).
My guess is that they'll indeed push onwards to Python4 as soon as possible. This being another attempt to make Python2 look as old and crufty as possible. "You're still on Python2? Wow, I'm on 4!". That's the type of political and psychological game the Python core dev team has been playing since 2008 with 3's release. Right alongside the 2020 EOL, another political move. Even though Python 2.7.'10' was never supposed to exist but they went back on that.
This because Python3 is mere technical churn, it is not true technical innovation.
The issue here is really one with the Python core development team. They have also adopted every niche feature into Python3 by whoever came along to ask for it.[2] This was done for the same reasons as the relative rush to rebrand the failed 3.x branch as 4. An attempt to stir up any hype possible for 3.0+.
They got so much wrong with Python3. Feature soup, unicode, and performance losses over 2. Unicode-by-default is the big deal and they didn't even get that right. They simply remapped unicode to str. Which for such a big breaking change, should've been UTF8 alongside other new languages such as Go.[3] But it's worse than that, Python3's feature soup continues in 3.6 there will likely be a 4th string formatting option[4] among throwing everything they can against the wall to see what sticks (while bloating the supposedly simple, "beginners" language).
While Python2 has been riding high in popularity[5], it has absolutely nothing to do with Python3. It's in spite of it.
There's good reason the core dev team "extended support" for 2.7. It's because they really did create a new, much less successful language and would've lost complete control of Python had they not done it.
Python3 is a language that looks mostly like Python, but is Python in name-only. Worse of all, it doesn't stand on it's own two feet with technical merits. I would personally recommend sticking with 2 until 3 ever makes sense, or finding something else to use like Swift or Go.
Unlike a web browser or another piece of software, the "latest version" of a programming language is not always in the end-user's best interests.
[0]https://twitter.com/gvanrossum/status/583346987925278720
[1]http://www.curiousefficiency.org/posts/2014/08/python-4000.h...
[2]http://learning-python.com/books/python-changes-2014-plus.ht...
[3]http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/
[4]https://www.python.org/dev/peps/pep-0498/
[5]http://www.tiobe.com/index.php/content/paperinfo/tpci/index....
Ruby managed the transition to unicode much better as they delivered 2x performance increase at the same time AND labeled the new version 1.9 instead of two. Much the same problem.
Yes python 2 is OK but it's legacy mode and people will move on. I think one of the selling points of python vs ruby is that its so often OK to just use system python(2) versus ruby where you really need to use something like rbenv. Selling point for ruby is that the community is absolutely obsessed with making good tools to facilitate working with it.
I have already in my mind decided the future is in languages that are designed with parallelism in mind. Another breaking change for that?
You're right though, unless someone takes on the mantle of CPython2, we're looking at being forced to move to 3 or find something else. I personally think '16/'17 will be the year(s) of Swift. With the Perfect server-side Swift framework[1], and more sure to come, it's very intriguing.
I'm a pretty conservative user myself, and dislike churn and feature bloat so I'm also fairly attracted to Go. I'm not suggesting that's Swift by any means. Go promised no breaking changes for a long time so it's a good choice to write long-lived software in (and who knows what will and won't end up being long-lived so we should always assume the latter).
[0]http://morepypy.blogspot.com/2015/03/pypy-stm-251-released.h...
> They have also adopted every niche feature into Python3 by whoever came along to ask for it.
You link to async/await as an example? You realize that's a huge deal and is an awesome feature right? It was something sorely missing, but replicated well with generators (thanks to Python being awesome) since Twisted and Python 2.4. Now is exactly the time to ratify it into the language. His complaints about concurrent programming are senseless as async/await are single threaded and avoid most of the concurrency issues you would typically run into when using threads. They also look a hell of a lot nicer and explicit than 'yield from x'.
That whole link[1] is garbage, I don't have enough space to comment on the many absurd statements it contains, but FYI the scientific community in Python is huge and they have been begging for a matrix operator.
You sound like you have a large Python 2 codebase that you don't have the time or resources to upgrade. That sucks. Don't channel that hate into Python 3 though. Start your new projects in it and have a play, you will like it.
1. http://learning-python.com/books/python-changes-2014-plus.ht...
Edit: That link is like reading the republican far-right news about how Obama is a Muslim sleeper agent. One of his complaints is that "The docs are broken on Windows and incomplete" when he's viewing them using an IE6 frame inside a Windows help file - it even tells him his browser is 'ancient', and he still complains some non-important JS is broken? Oh god. Or how getting rid of .pyo files is a terrible thing, or how type annotations will eventually destroy all that is holy about dynamic typing....
Just because you agree with part of my post and arguments doesn't mean you have to downvote. I had the GVR quote about semver to directly responded to and added to the original post, which is more than most comments.
Anytime I post something critical of Python3 it seems to be a big tug-o-war between those who want to shame me and those who want to show approval. I do it because someone has to say this stuff because I believe the silent majority sees it this way and I frankly find the vocal Python3 promoters to be the loudest of the bunch. There's nothing wrong with other viewpoints unless you're wrong. :)
By the way, Mark Lutz is well respected. He has been teaching Python for decades.
But... that's a corner area of Python. Not everyone needs GIL-less STM, and arguably if you're using tonnes of threads maybe you're doing it wrong? Perhaps you should try asyncio :)
I mean that reason doesn't even make sense - I'm not using PyPy3 because of the GIL. Great, so uhh what about Django apps? What about small scripts and projects? What about using it for anything other than highly threaded applications that benefit from no GIL?
> Just because you agree with part of my post and arguments doesn't mean you have to downvote
I didn't (and I wouldn't have), I just upvoted after reading "This being another attempt to make Python2 look as old and crufty as possible" - thinking you viewed this in a positive light.
> frankly find the vocal Python3 promoters to be the loudest of the bunch
I see the opposite. I see lots of people angry about a statement being turned into a function, angry at not understanding encoding and angry at the Python developers. People demanding a JIT in cPython, people crying about type annotations, etc. Plus a shedload of FUD.
I'm sorry, your comments reek of someone angry for not very good reasons and I can't work out why. Python 3 is a much much nicer language to work with, it's more consistent and has less WTF's (along with far less UnicodeEncodeErrors). I took the plunge a year ago and won't ever look back, coding in 2.7-8 at work hurts.
I know Mark Lutz is well respected but that doesn't make some of his comments on Python 3 less silly. Anything that has been added to Python 3 has a comment explaining why it sucks, and most of those explanations are senseless. Even things like the statistics module - apparently that sucks because NumPy is better? He implies that should be bundled instead. :/
The matrix operator saves 3+ lines of Numpy code (and is a common operation). This of course sucks because "it's not used by the core language". Oh and it "expands Python's complexity and learning curve needlessly", despite not being used by the core language. Ok Mark.
Example, I completely agree with all of Lutz's comments and can't see how someone could see it another way. I'm trying though because I'd love to be onboard (I'm sure Mark would too)- but I'd be lying to myself currently to turn a blind eye and move to Python3.
On the benefits of Python2 having production-ready PyPy. It's more than GIL free Python. You only discussed that, but the general performance is next-level plus some from CPython3.
>Not everyone needs GIL-less STM,
You don't need anything, until you do. :)
>What about using it for anything other than highly threaded applications that benefit from no GIL?
That's a "niche feature" like building async IO, but it actually matters because Python3 cannot and likely won't have it. When it does, it'll most likely remain 3.2. While Python2 has many ways to achieve async IO.
>Great, so uhh what about Django apps?
What about them? Django is dramatically superior on Python2/PyPy. I use Django on PyPy with gunicorn and nginx and I assure you I have no worries about any CPU bottleneck no matter what I do.
>people crying about type annotations, etc.
Most of the features in Python3 thus far have been gimmicks, and some are downright embarrassing like type annotations.
Python2 is the premier development platform for me. I can use PyPy and I still have the Python3 migration available. Why would I be in any rush when I only lose moving to 3 today. It just doesn't make sense.
I find it amazing folks have been banging down the gates wishing there was no GIL in Python- it's here but Python2 only. Therefore no longer a big deal. Not to mention the pure single threaded CPU performance improvements available to 2. :) That to me reeks of pure desperation.
Frankly, the only possibility of an "upgrade" available from CPython2/PyPy is not Python3. It's Go, Swift etc.
- backwards compatible with the latest release of Python 2
- contain all features of Python 3 in some form
I think this will result in a very speedy adoption.
In the future I propose the following numbering scheme: for any N > M, Python N contains all features of Python M and is backwards compatible with Python M if and only if M divides N.
It is possible to work in a subset of python2 and python3 that is syntactically valid under both interpreters but this is not what you are suggesting.
The syntax between 2 and 3 is essentially the same. A few minor tweaks here and there, but nothing major. Your point is a bit pointless because changes to the language that are not on the syntactical level (i.e unicode/bytes) cause the meaning of the code to change, despite the syntax being the same.
> - backwards compatible with the latest release of Python 2
> - contain all features of Python 3 in some form
I'm lost for words.
Feature: print function.
Implementation: from __future__ import print_function
Yes, that magical, backwards-incompatible, print function has been in Python 2 all along!
Feature: unicode strings
Implementation: from __future__ import unicode_literals
Amazing! The magical, backwards-incompatible unicode strings backported to Python 2 with one single line.
I could go on and on.
Except it's not even slightly close to that is it. unicode_literals is something completely different.
How about removing old style classes? Is `class x:` old style or new style in Python 2, in this imaginary interpreter of yours? How about the default object comparison being sane in Python 3. How about the changes to builtins returning iterables over lists? How about the import system being more sane? How about removing backticks? How about actually handling the unicode differences?
I could go on and on, and I hope your answer is not 'well we just need more __future__ imports don't we'.
The question is whether programming in one version vs the other is more enjoyable.
So every program you write for Python3 will also be compatible with Python4, unless you use the deficient kinds of version-checking that the linked article extols against.
That's what this article is about, anyway. Based on the issues with Py3 I'm quite confident that switch from 3 to 4 will be similar as from 1 to 2.
goto = {2:fn2, 3:fn3}
if six.PY in goto :
goto[six.PY]()
else :
sys.stderr.write("ack, no python to run!\n")
sys.exit()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 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.
And also handle reading from files correctly, or list file names from the os, or anything that communicates outside of the python interpreter.
The main reason why python 3 was created was to manage these complexities, and even then some people[1] say it wasn't done properly.
[1] http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/
But more seriously, probably good advice. Isn't "explicit" one of the Pythonic mantras?
But I'm wondering if any code written today really will survive until "Python 4"?
That'd be wild. What do you call something that is even MORE backward compatible? Going retro.
Stop Python's little tin god before he kills again.