Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages!

Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language.

I remember when this kinda happened with PHP and versions 4 and 5. I still run across hosts who default to PHP4!? WTF? Its 2012!

Is PYthon3 really that new that you shouldn't pick it up or is this developers still refusing to update?



Python 2 versus 3 isn't anything like PHP 4 versus 5.

The problem is that there are a few minor but backwards-incompatible changes to the syntax in py3. Libraries can't update until all their dependencies update. And web frameworks are some of the most complex software with the most dependencies, so they're updating last.

It's still pretty much the same language behaving in the same way, though. If you know Python 2 really well, it'll take all of five minutes to get accustomed to Python 3. Just don't worry about it and learn 2 until people stop telling you otherwise. :)


"Don't worry, migration from Python 2 to 3 is really easy. It'll take 5 minutes to learn."

"Migration for libraries from Python 2 to 3 is really hard. It's taken them a few years and counting."

??


Right. Learning Python 3, once you know 2, is really easy.

Library maintainers have two problems: they have to twiddle their thumbs until all their dependencies have ported, and then they have to get their code running against both 2 and 3. The former is exactly why I'm saying to use 2 for now, and the latter is easy if you only support 2.7 but rather more difficult for projects that still want to run on some archaic thing like 2.3.


Python3 isn't much different from Python2. It's not like you have to re-learn Python when you switch from 2 to 3.

In a nutshell: print() has become a function instead of a statement. The standard library has been made more consistent. Built-in iterators are lazy by default. The two string types (str and unicode) are properly redefined as 'bytes' and 'strings'.


In practice, for MOST developers, the changes between 2 and 3 are minimal. Offhand, print is a function, and there's no distinction between unicode strings and ascii strings anymore. If you do a lot of "low level" networking involving byte strings, you'll notice the difference, because you can't just jump between bytes and strings anymore.

It's this distinction that's delaying a lot of networking related libraries from porting to Python 3 - basically, it's going to be a long, buggy journey. Libraries such as Twisted, have very old codebases - old enough that some of the practices aren't the best, even for Python 2 code. Upgrading it to Python 3 will introduce quite a few breakages.

There's a lot more that I can't think of right now, but I'm sure someone else can cover off other differences.

There's no reason not to learn both - I use Python 3 for a few personal projects, and Python 2 for work.


For the vast majority of projects, upgrading (or working with both PY2 and PY3 at the same time) is not that big of a deal unless the project you're working on is really, really old (2.3 days). At work we run unittests targeting different python versions and the most time I've spent changing a typically 4k loc project's codebase to work on both 2 and 3 has been around 4 hours. The average around 1.


Python 3 is not "really that new" and Python 2.6-2.7 is not "old" in any way.

In fact we have: pre-2.4 (really old, preinstalled on old Redhats), 2.4-2.7, 3.x

Python 3 is curing problem with variable visibility (and if you do not write in "pure" functional way - you will never see this problem) and unicode strings. Other differences is not so "revolutionary".


> (and if you do not write in "pure" functional way - you will never see this problem)

Could you explain this a little more, please?


I assume he's talking about the `nonlocal` keyword introduced in py3, which allows overwriting names defined in outer-but-not-global scopes.


Yes, eevee is right.

I'm talking about http://www.python.org/dev/peps/pep-3104

New keyword nonlocal and ability to have better closures.


> I am concerned that I will learn something and create app's which within a year will be out of date

Don't worry about that. Start with Python 2 and if you ever have to move to Python 3, it will be fairly easy.

The same thing happened in the PHP world during the switch from 3 to 4 and then 4 to 5. The move from Python 2 to 3 will probably be smoother.


The differences between Python 2.7 and 3.x are going to be minimal. You can mostly write Python 3.x style code in 2.7 and still have access to all of the libraries that have not ported their code yet.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: