views:

1366

answers:

6

I visited Slashdot this morning to find out that Python 3.0 has been released. I know C# and Perl, but have wanted to learn Python for some time, especially after I saw its ease of use to create useful tools, not to mention its use in game scripting.

My question is, how does the intentionally backwards-incompatible release of Python 3.0 affect adoption, and should I learn Python 2? Or should I take the dive and learn Python 3.0 first, and wait for the libraries to be ported?

+4  A: 

Python 2.6 is the bridge to 3.0.

Backward compatibility is a complete non-issue. It's minor, isolated and specialized. There are only a few things that most people will notice are incompatible, primarily the loss of the print statement.

There's a specific conversion strategy and tools for checking your code for compatibility and making the necessary changes.

It will be painless. Learn with 2.6, using the 3.0 features. It'll all be good.

S.Lott
+11  A: 

I don't think it will affect adoption in the long run, but it certainly won't be painless. Python's motto and strategic advantage has always been "Batteries Included". This was not only due to the Standard Library, but also due to the many external libraries. Will libraries like NumPy, SciPy, WxPython, PyGame (just to name a few) work from day one? It will take some time foreverything to consolidate. Also, what about older systems that have an old 2.x version of Python. In few years from now I may found out that I need to update a library. Will the library author continue to support the 2.6 version so that I have a choice? For how long will 2.6 distributions be available for legacy systems? A change of this size is never easy.

For someone starting to use Python now, I suggest to go with Python 2.6, which is actually a bridge between the two worlds.

kgiannakakis
We have just a few Python scripts at work and the new way to use the print functionality means that we have to plan a transition where everyone upgrades to Python 3 at the same time, or the script won't run on all machines (depending on wether we change it or not), so I think it is a real issue.
Lasse V. Karlsen
@lassevk, Python 2.6 sounds like what would work best for migrating in your case. You can use the print statement like old versions, and also use the new function by using 'from __future__ import print_function', so that you can migrate incrementally. The same applies to unicode_literals.
Adam K. Johnson
+10  A: 

I think it will hurt for a time, but not as bad ad PHP4 to PHP5 is. As is mentioned by someone else, the biggest issue is "Are the libraries I use ported?" There will continue to be dual releases of Python 2.X and 3.X for a time for the purpose of slowly transitioning people. is it worth it for a large system that is in maintenance mode? Probably not (until something bad happens).

There is a great porting guide though and they have tried to make the transition as easy as possible. The one note I would add to it is "Make sure you are importing all the __ future__ statements possible (like print as a function). I don't know how the 2to3 script handles it but that at least gets you some of the code changed and tested.

portingGuide = """ For porting existing Python 2.5 or 2.6 source code to Python 3.0, the best strategy is the following:

  1. (Prerequisite:) Start with excellent test coverage.
  2. Port to Python 2.6. This should be no more work than the average port from Python 2.x to Python 2.(x+1). Make sure all your tests pass.
  3. (Still using 2.6:) Turn on the -3 command line switch. This enables warnings about features that will be removed (or change) in 3.0. Run your test suite again, and fix code that you get warnings about until there are no warnings left, and all your tests still pass.
  4. Run the 2to3 source-to-source translator over your source code tree. (See 2to3 - Automated Python 2 to 3 code translation for more on this tool.) Run the result of the translation under Python 3.0. Manually fix up any remaining issues, fixing problems until all tests pass again.

It is not recommended to try to write source code that runs unchanged under both Python 2.6 and 3.0; you’d have to use a very contorted coding style, e.g. avoiding print statements, metaclasses, and much more. If you are maintaining a library that needs to support both Python 2.6 and Python 3.0, the best approach is to modify step 3 above by editing the 2.6 version of the source code and running the 2to3 translator again, rather than editing the 3.0 version of the source code.

For porting C extensions to Python 3.0, please see Porting Extension Modules to 3.0. """

Ed
+1  A: 

I don't think anyone expects Python 3 to be instantly adopted. As far as I know, GvR is still planning on supporting the 2.x line for several more years while Python 3 gathers momentum.

I think the signal that the transfer is complete will be when the O'Reilly books update to 3.x. Until then, it's transitional. :)

J.T. Hurley
+1  A: 

For me, personally, the moment I start using it for real work (over 2.5) will be when it becomes ubiquitous among linux distributions (particularly debian/ubuntu). At the very least, it needs to be in an apt repo somewhere.

Jeremy Cantrell
A: 

I can't really buy the response that "it will be painless". The choice to not make a major language backwards incompatible is a tough and conscious decision. But, that does not mean that the decision to do so may not spell its death?

Why would developers learn python 3.0, when the language has departed so far out that major libraries aren't safe to be used in production. Not to mention that major web frameworks like Django aren't supporting it at the moment.

I understand that python 2.6 offers a bridge to 3.0. But, why create 3.0, when 2.6 was supposed to be transitioned strategy to port over to new syntax and features? The amount of double maintenance and cost of ports should have weighed on such a drastic decision. It almost seems as if they had the balls to bite the bullet, but not really.

So, to answer the question: I am not sure if learning python at this juncture is worth the effort. I rather have the dust settle before making the plunge

Salman Paracha