Ask HN: start with python 2.6 or 3?
if you were learning python right now as your first language and you wanted it to play well with others (django, scipy, matplotlib, GAE etc) - do you start with something stable with loads of documentation and then migrate to python 3 (heck it's 3.1 already) or do you skip the mental overhead of unlearning some things that'll get baked in by using 2.6?
17 comments
[ 3.3 ms ] story [ 43.8 ms ] thread<BEGIN RAMBLING> If the users don't drive the library authors/maintainers to make their code compatible with Python 3, then we'll have to wait a very very long time for the 2.x branch to go away. I'm not saying Python 2.x is bad in any way. It just takes too much effort to maintain separate codebases for separate versions of the language. Also, I'm sure the language developers could do something much more useful with their time if they focussed on one version of the CPython implementation. <END RAMBLING>
Being a trailblazer can reap rewards in the long run.
EDIT: specifically some of the libs you mentioned. If you have time, I agree go w/ 3.0- you'll know the libs that much better as well if you help port them.
You're thinking that this is a significant thing. It isn't, at least not if you become a somewhat competent programmer.
Programming has very little to do with programming language details.
In fact, there's a reasonable argument that the more languages you know, the better programmer you're likely to be. Unfortunately, the difference between 2.6 and 3.1 probably isn't enough to help you in this regard. It is, however, enough to help you see some issues wrt language design.
Note that both Python 2.6 and 3.1 are considered stable production releases, but if you don't know which version to use, start with Python 2.6 since more existing third party software is compatible with Python 2 than Python 3 right now.
If you're just learning to program now, you'll have an easier time if you stick to the officially sanctioned features of Python, rather picking up bad habits from deprecated back roads. There aren't many of them in Python 2 compared to some other languages, but if you want to be safe, Python 3 was meant to eliminate as many of those as possible. You'll get a similar benefit if you follow the official Python 2.6 tutorial first, before reading introductory Python books that were written before Python 2.6 was released.
To be super specific, these are the things that you should try to stay up to date on:
1. Unicode support in strings
2. "New-style" versus "old-style" classes
3. The "with" statement, and context managers
4. Generator functions and expressions, versus list comprehensions and plain ol' for loops
If you watch out for these, and read the "What's New in Python X.Y" documents for each version between the one you started on and the newest release, the transition shouldn't be too hard.
The projects you're depending on may also offer some hints about when they'll do the 3.X transition. SciPy depends on Numpy, which depends heavily on the Python 2.X C extension API and will take a long time to convert. Django is basically pure Python and can probably convert sooner. GAE is Google's infrastructure and will probably be 2.X for years.
With that said, some libraries still haven't made it to Python 2.6 let alone 3.0. For instance, I make use of NumPy which was compatible with 2.54 but not 2.6 the last time I checked.
After working in a bit of py3k, I've found that "small things" such as using print() as a function rather than a statement comes more naturally than in Python 2.x, mostly because the latter doesn't complain about it.
Other things like xrange()'s departure in py3k as range() becomes a true iterator -- that's something you'll have to be cognizant of.
My advice is if you want to get a large project done, with support from popular and existing frameworks, go with the 2.x branch. If you're whipping up some disposable scripts, practice with py3k. And even if you're not, fire up py3k anyway.
One of the great Google Summer of Code projects this year is the inverse to the 2to3 tool -- 3to2 -- with the forward-thinking intention of making it easier to maintain one branch of code in py3k. It isn't a magic bullet by any means, but should definitely encourage the transition from Python 2.x to 3000.
Start with 2.6 but consider 3.0 changes in mind like exception base, print statement. Start practice 3.0 convention using 2.6.
I think, atleast two to three years of development for people to port all their projects to python 3.0.
Sure, you will miss many things, but you are on the way.
If you don't choose to use any libraries that require v2.6 or older right now, then I'd encourage the choice of v3.1. I'm hoping all libraries will run with v3.1 given enough time.