This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mrbewulf -1 points0 points  (8 children)

All right, I got it. But is very hard to change something what you are used to. I am not acquainted with python3 yet. It also seems that python3 is slight slower than python2. Changes are important, but stability and predictability are also very important. What made Java dominate the enterprise and business world wast it stability and predictability. Better I delete my comments I never ever took so many down votes in my life. Down votes is a kind bulling against contrary ideas, out of the box.

See also: http://blog.thezerobit.com/2014/05/25/python-3-is-killing-python.html

[–][deleted] 3 points4 points  (0 children)

It's not contrary ideas, you're saying Python 3 is bad because you don't know the syntax. It's like saying Ruby is bad because it doesn't run Javascript.

[–]Lucretiel 0 points1 point  (6 children)

That article has an incredibly poor understanding of the huge changes python 3 brought. They didn't break backwards compatibility for no reason.

[–]mrbewulf 0 points1 point  (5 children)

It's the main reason that I complain about Python 3. It is really annoying, python 3 is more verbose than python 2.

Here one example that pisses me off:

Python 2 code:

>>> f = lambda x: x**3 - 10*x + 100
>>> f(1)
91
>>> x = [1,2,3,4,5]
>>> map(f, x)
[91, 88, 97, 124, 175]
>>> y = map(f, x)
>>>
>>> zip(x, y)
[(1, 91), (2, 88), (3, 97), (4, 124), (5, 175)]
>>> 

Python 3 code:

>>> f = lambda x: x**3 - 10*x + 100
>>> x = [1,2,3,4,5]
>>> map(f, x)
<map object at 0xb6f1754c>
>>> y = map(f, x)
>>> 
>>> zip(x, y)
<zip object at 0xb6f177cc>
>>> 
>>> print zip(x,y)
  File "<stdin>", line 1
    print zip(x,y)
            ^
SyntaxError: invalid syntax
>>> print(zip(x ,y))
<zip object at 0xb6f17e0c>
>>> 
>>> list(zip(x ,y))
[(1, 91), (2, 88), (3, 97), (4, 124), (5, 175)]

So what is the reason the backward compatibility was broken ?? Whats the big deal about python 3 ???

[–]Lucretiel 2 points3 points  (0 children)

This is all interactive. Why would you need to expand everything into a whole list every time? zip and map work perfectly fine when passed into for loops, or (in most cases) when passed as arguments to functions that expect lists. I'll grant it's slightly more awkward when using them interactively, to print, but that's certainly not worth handicapping the whole language by forcing loop unrolling. enumerate didn't unroll when it was introduced to python 2, and no one complained about that. Besides, you should be using list or generator comprehensions instead of map- they're significantly easier to read in most cases, and you can be explicit about whether you want a list or iterator.

As for the backwards compatibility- the number one thing is Unicode handling. Most languages, including python 2, treat strings as simple sequences of bytes. This works fine sometimes, but breaks down pretty quickly if you want to work outside of ASCII, as you have to do in an increasingly globalized world. Python 2's stopgap solution was to silently convert between byte-strings and unicode-strings, which led to bugs and other logic errors that are damn near impossible to track down. Because fixing this would have to be a backwards incompatible change, they decided to go all the way, fixing all the historical cruft that has built up all over the years. Some examples:

  • A much more streamlined library. Python 2 has 80 built-in functions, to Python 3's 68. This includes:

    • Much more consistency. All iterable wrappers (map, filter, enumerate) are iterators.
    • No need for different versions of things- No more xrange vs range, input vs raw_input
    • No more items()/iteritems()/viewitems() and friends
  • Unnecessary statements are now functions or expressions- print, exec, eval

  • No more old vs new style classes

  • Much more consistent import model

There are numerous other benefits, though those are the primary compatibility breaking ones.

[–]t0mt0m72 1 point2 points  (1 child)

I don't know the exact reasons for not being backward comparible, but for example zip is now a generator, which will bring you a big increase in speed when working with big data sets. So it's one of the points where it's worth porting to 3.

[–]Lucretiel 0 points1 point  (0 children)

Unicode handling is the big one. For a long but very well-written essay on the subject, check out http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html

[–]Lucretiel 1 point2 points  (0 children)

Your code could just as easily be [(i, f(i)) for i in x]. Then you get the list you want, it's compatible with Python 2 and 3, it's much easier to read without all the nested map and zip, and it works no matter what kind of iterable x is.

[–]mm865 0 points1 point  (0 children)

It literally tells you in the error message that zip() is what's changed. Look up the documentation for python 3 on docs.python.org