This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Python

Python 3.0 makes a big break

By Joab Jackson on October 15, 2008 (4:00:00 PM)

Share    Print    Comments   

Typically, each new version of the Python programming language has been gentle on users, more or less maintaining backward compatibility with previous versions. But in 2000, when Python creator Guido van Rossum announced that he was embarking on a new version of Python, he did not sugar coat his plan: Version 3.0 would not be backward-compatible. Now that the first release candidate of Python 3.0 is out, with final release planned for later this month, developers must grapple with the issue of whether to maintain older code or modify it to use the new interpreter.

Developers hate it when a new version of a language doesn't work with the code written for older versions of that language, but for van Rossum, the radical upgrade was necessary. The language was becoming ever more weighed down by multiple ways of doing the same task, and ways of doing tasks no one ever actually did.

"The motivation for 3.0 was to have one specific event where we did as much of the backward incompatibility all at once," van Rossum says. The idea is to "give the language a better foundation for going forward."

Naturally, some stirrings of discontent can be felt across the Python community.

"Python is pretty much determined to remove itself from consideration from various kinds of international projects like the one I work on. We're already catching flak from people due to a few things that were valid in 2.2 that are not valid in 2.3," bemoaned one developer in the comp.lang.python newsgroup.

"For an operating system distributor, Python 3.0 represents a large potential change in their repository of packages for relatively little benefit in terms of resulting functionality," says UK Python developer Paul Boddie.

What changes?

In a way, Python has been a victim of its own success. "The original idea for the language had a much smaller scope. I really hadn't expected it to be so successful and being used in a wide variety of applications, from Web applications to scientific calculations, and everything in between," van Rossum says.

Van Rossum first created Python in 1990, as an open source, extensible, high-level language that he needed to handle some system administration duties. Today, Python is one of the most popular languages used world-wide. In March 2008, Austrian researcher Anton Ertl ranked programming languages in terms of their popularity as gauged by the number of postings in Usenet newsgroups. Python proved to be the third most-discussed language on Usenet, right after C and Java, ahead of such stalwarts as C++ and Perl.

When it comes time to teach someone how to program, often the easiest programming language to use is Python. It is the Basic of today, though more elegant to work with than Basic ever was.

Yet Python's simplicity was being threatened by the unchecked growth of the language, van Rossum says. Throughout the '90s, new functions and features were bolted onto the language, and inconsistencies started popping up across the platform. "We were slowly losing the advantage" of simplicity. "We had to break backward compatibility. The alternative was unchecked bloat of the language definition, which happens very slowly and almost unnoticeable."

Python.org has a list of changes to the language. Some are small, and will go unnoticed by most programmers. Others can be relearned quickly.

"Most of the differences are in the details; the general gist of the language, how people think about the language and the capabilities are pretty much unchanged," van Rossum says.

For instance, the print statement got turned into a print function; you must now put parentheses around what you want to print to the screen. The change allows developers to work with print in a more flexible and uniform way. If someone needs to replace the print function with some other action, it can be done with a universal search and replace, rather than rewriting each print statement by hand.

Another change: The language only has one integer type, instead of the former distinction between long and short integers, which van Rossum characterizes as worthless.

Another tangle of cruft that has been pruned back is something called "classic classes." Python version 2 has two sets of classes, each with its own format. "There was a lot of machinery in the Python virtual machine that was either special-casing classic classes or double implementations with version for classic classes and another version for new-style classes. This was implementation bloat," van Rossum says. So, after six years of campaigning to get people to move to the new classes, the developers of Python 3 have put their collective foot down and are doing away with the classic classes.

Perhaps the biggest change that takes place with Python -- and the one that will require the most rewriting of existing code -- is the new way Python deals with bytes and strings. Originally, Python represented all input and output as strings. When Python was used more in casual settings, most strings that went through the interpreter could easily be represented by the standard ASCII character set. But as the language's use grew to global proportions, more and more users started using Unicode to support a wider array of language characters. To Python, Unicode looked a lot like 8-bit binary byte strings, which could be passed along to the interpreter as part of the output from another program. In some cases, the interpreter would confuse binary data with Unicode-encoded strings, and it would choke, big-time.

The answer? Define a new object class for handling bytes -- a first for Python. Also, redefine strings as Unicode. And then keep the two clear of one another. In other words, the byte type and string type are not compatible in Python 3.0.

"If you ever make the mistake of passing bytes around where you think they are text, your code will raise an exception almost immediately," van Rossum said.

Conversion and converts

van Rossum admits now that he didn't think much of the transition difficulties when he first started thinking about Python 3.0. "In 2000, the community was small enough that I thought that I would just release a new version and people would fix their code and that is that."

In the feedback process with the user community though, the core developers started hearing more clamor for a smooth transition process. They needed tools.

This is the role of the recently released version 2.6 of Python, which will serve as a transition version of the language. Users can easily upgrade their code from earlier versions of Python to version 2.6. The 2.6 interpreter will offer warning messages about aspects of the program that will no longer fly with version 3.0.

"We're encouraging people to upgrade to Python 2.6," van Rossum says. "2.6 can help you find the anachronisms in your code that you will need to change to be prepared for 3.0."

The development team also created a transition tool called 2to3 that converts Python 2.6 code into Python 3.0 code. You can then run your older code in 2.6, rewriting it until all the warning messages have been eliminated, then use 2to3 to convert the code into Python 3.0 specs.

Of course, since Python is a dynamic language, where types are not explicitly declared, there are a lot of cases where a translation tool will not help much, but it should help with the mundane tasks, such as changing print statements into print functions.

Even with this tools in place, van Rossum admits that the migration of the user community will be a slow haul, and not all Python shops will make the transition.

For instance, the printing preparation company Aahz Maruch works for, Page DNA, relies on 200,000 lines of Python code in its core revenue-generating operations. "It would be a huge job" to translate this code into Python 3.0, Maruch says. He says the company will wait for a few years for the automatic translation tools to improve. "We haven't even talked about 3.0 -- it's at least two or three years away."

Others are more skeptical about the necessity of the upgrade.

The "implementation of Python 3.0 gives relatively little attention to [current] issues [modern programming languages face], such as performance, pervasive concurrency, or the provision of a renewed, coherent bundled library," Boddie says.

He says there is a danger that Python 3.0 may not be seen as a necessary upgrade for most developers and, as a result, it could lose its status as the de facto Python in much the same way Windows Vista hasn't become the de facto Windows over its predecessor Windows XP.

Today, the chief implementation of Python is CPython, which is a Python interpreter written in C. However, Boddie notes that other implementations exist, such as JPython (Python in Java), IronPython (Python written in Microsoft .Net's Common Runtime Language), and PyPy (a Python interpreter written in Python).

"I think that Python 3.0 may actually focus attention on other Python implementations, particularly if these do not pursue Python 3.0 compatibility as a priority," Boddie suggests.

Nonetheless, the core development team is confident the tide will turn their way, eventually. "I expect that most people will be using 2.6 a year from now. Only bleeding edge people will be using 3.0," van Rossum says. However, "if you're starting a brand new thing, you should use 3.0."

Share    Print    Comments   

Comments

on Python 3.0 makes a big break

Note: Comments are owned by the poster. We are not responsible for their content.

Python 3.0 makes a big break

Posted by: Anonymous [ip: 24.127.74.89] on October 15, 2008 10:09 PM
Meh...You don't have to upgrade "now".

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 67.88.249.34] on October 15, 2008 10:23 PM
I am currently learning python and decided to just jump to 3 and start there. The orielly book states the differences and so far every difference between 2 and 3 I think was a good change. Especially when learning the language from scratch. Changing your code always sucks but inconsistencies make coding less fun when standards over ruled because of history.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 69.69.28.85] on October 15, 2008 11:39 PM
Python 3.0 totalyl ROCKS dude. Excellent tools

www.privacy-tools.at.tc

#

Re: Python 3.0 makes a big break

Posted by: Anonymous [ip: 141.161.127.75] on October 16, 2008 12:03 AM
The only "excellent tool" here is you, spammer moron.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 89.138.240.199] on October 15, 2008 11:44 PM
Okay I've been wanting to learn Python for quite some time, would someone provide resources to learn Version 3 stuff? By the time I can write useful stuff 2.5 will probably be history.

#

Re: Python 3.0 makes a big break

Posted by: JackieBrown on October 16, 2008 12:03 AM
Two posts up seem to indicate an oreily book on the subject...

#

Re: Python 3.0 makes a big break

Posted by: Anonymous [ip: 99.189.255.92] on October 16, 2008 01:13 AM
check out "byte of python" google that or "swaroop" the blog of the guy who wrote it. he has updated his book for 3

#

Re: Python 3.0 makes a big break

Posted by: Anonymous [ip: 128.138.58.108] on October 16, 2008 03:50 AM
Take a look at the Python 3.0 official tutorial:
http://docs.python.org/dev/3.0/tutorial/index.html

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 24.12.7.187] on October 16, 2008 02:43 AM
I think you meant Jython when you said JPython.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 62.92.118.68] on October 16, 2008 09:13 AM
Dinosaurs once phased out to leave space for more agile moving species. The python is finally biting something too big for it to digest, and as usual it is Corporate Programming that is denying a language to develop as nescessary. Algol, cobol, fortran, c++ and now python. What's next? Ruby?

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 86.128.248.50] on October 16, 2008 10:52 AM
I really like python, but this was a foolish decision and python must revert it or become fragmented and replaced. :-(
The hope is someone creates a way of using python 2.x libs in python 3. Some kind of translation layer.
They don't have to do a perl and keep every previous syntax so you can mix them to create write only code, but we need those 2.x libs! Read your history and compare languages and platforms that did and didn't maintain backwards compatibility. This really upsets me because I really like python and was just beginning to convince people at work we can use it.

#

Re: Python 3.0 makes a big break

Posted by: Anonymous [ip: 78.109.15.2] on October 16, 2008 11:09 AM
Your comment is a bit over the top and this article also does no point in highlighting the plan.

Python 2.6 already provides some Python 3 features and the subsequent 2.7 and 2.8 releases will gradually introduce more and more so that moving over at one point will not be so disruptive.

Then there is the 2to3 tool which will take your code and convert it as much as possible to the 3's syntax.

There is no one telling you to move to 3.0 NOW. 2.6 just got released and a lot of people are only now ditching 2.3 and moving to 2.5 or perhaps 2.6. So the whole move to 3.x is years into the future.

#

Re(1): Python 3.0 makes a big break

Posted by: Anonymous [ip: 86.128.248.50] on October 16, 2008 11:44 AM
"If it ain't broke, don't fix it."
I have no doubt many useful libs that are thought of as 'finished' by their author won't be moved up to python3.
Also you won't get large companies to agree to changing existing working internal code because the language has changed and the programmers want to use the latest. They will quite rightly expect you to be able to call the old code from the new when need be, or you can't work in the new.
This harms python as people including myself will now see developing on python like building on sand.
All the main stream languages I can think of go out their way to avoid this.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 74.39.77.13] on October 16, 2008 02:07 PM
This is going to be a huge mess for us. We want to go to 3.0 but our hands are tied on this. We use Twisted, Beautiful Soup, Numpy, Scipy, Pygame, some visualization packages, and more I'm forgetting. We can't do much in the way of going even to 2.6 until that stuff gets there. And then it's going to take a long time for all those 3rd party packages/libs to go to 3.0. Some might not ever get there. I think this is going to stop us from going to 3.0 for at least 3 years, maybe even 5. And the worst part is that none of these 3rd parties talk squat about their plans for moving to 3.0. They have no statement of plans, no timeline, and a few of the libs haven't been updated in years. what a mess.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 86.145.238.168] on October 17, 2008 01:35 AM
Rubbish - cleaning up a language is the right thing to do. There is a solid upgrade plan with plenty of tool support to help users migrate. Old C code doesn't compile with new C compilers and no one complains. The language developers have come up with reasonable upgrade path and libraries will and are following suit. No need to panic.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 68.91.35.128] on October 18, 2008 08:11 PM
@74.39.77.13: You're jumping FAR too soon, friend. Python 2.6 was just released a few weeks ago; THAT should be your next step, once the libraries that you need have been released for it. Once your code works nicely on that, just enjoy the experience and feel the power for a while; no worries. Once the libraries that you need have been released for 3.0, THEN begin planning the jump to that version.

The "early adopters" are prepped to endure the pain of the early transition; your post makes clear you're not one of them, so WAIT! There's no shame is using what's stable, mature and well-understood. It's what the bulk of professional Python programmers do - wait for all the batteries to be included, THEN upgrade. :-)

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 85.72.146.144] on October 19, 2008 09:11 AM
As a Perl fan who will soon be forced to learn Python simply because of the latter's growing popularity, I say: "Yay!" Perl is always backwardly compatible. There are obvious discontinuities such as the introduction of threads in 5.8.x, but it is a design goal and Perl tradition not to break programs that ran on earlier versions of Perl. So this unpopular move by Guido may well encourage more use of Perl and less of Python.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 24.207.95.37] on October 19, 2008 07:35 PM
Multiple versions of python can (and currently do) peacefully reside in the same PREFIX installation area.

Distros can install both 2.6 and 3.0, and decide which binary (/usr/bin/python2.6 or /usr/bin/python3.0 is linked to /usr/bin/python).

/usr/bin/python is really just for the lay user who's launching "python" from the command line.

Anyone who's developing serious scripts or applications should be specifying the actual version their code have been tested against.

#!/bin/env python2.6
or eventually..
#!/bin/env python3.0

I don't know why people are panicking about 3.0; this is no different than distros including Python2.4 and Python2.5 on the same machine. Or software developers making the jump from gcc 3.4 to 4.x.

#

Re: Python 3.0 makes a big break

Posted by: Anonymous [ip: 75.56.58.175] on October 19, 2008 11:28 PM
> Anyone who's developing serious scripts or applications should be specifying the actual version their code have been tested against.
>
> #!/bin/env python2.6
> or eventually..
> #!/bin/env python3.0

This is a good way to get in troubles.
What will you do when someone installs 2.7?
Will you upgrade all your code and replace python2.6 with python2.7?
What about the guy that stayed with 2.6?


Not to mention that a seciour python project works with multiple python versions; at least 2.3+ is the standard these days.
I even had requests to support 1.5... and most of the time I was able to do it!

I agree with most posters... this incompatibility with 3.0 is a HUUUUGE mess.

Igor

#

Re(1): Python 3.0 makes a big break

Posted by: Anonymous [ip: 128.196.124.115] on October 27, 2008 04:30 PM
You don't have to do anything if someone installs 2.7. 2.6 will still be there and your application will still run against 2.6. That's why it's the preferred method. If you tested against 2.6, you wouldn't want your app to run on a newer version without complaining.

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 128.196.124.115] on October 27, 2008 04:21 PM
I thank the Python community for not caving in on maintaining their extremely high standards. This is exactly why Python will remain a relevant language far into the future. Other high-level languages that try to maintain backwards compatibility suffer from so much function and operator bloat (php, perl...) that they begin to get complicated and confusing, so people stop using them and move on to the next hot language. Trimming the fat means that won't happen with Python. Now just cross your fingers for Perl 6....

#

Python 3.0 makes a big break

Posted by: Anonymous [ip: 202.20.192.177] on November 03, 2008 02:26 AM
I am wonder how many people still use python since nowadays web programing is booming which can be mostly done by javascripts. Hence, I don't know the reason why we need to non-compatible new version of python. I suggest to develope high compatible python or new language which can replace javascripts by solving the limit of javascript.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya