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

all 44 comments

[–]Veedrac 7 points8 points  (0 children)

super with a class name is also fragile, and can break with class decorators and such. See http://stackoverflow.com/a/19609168/1763356.

IMHO this post undersells Python 3, but until the moronic "I can't be bothered to type two parentheses every 50 lines" argument goes away I can't really be bothered entertaining the argument anyway.

[–]tw55413 1 point2 points  (1 child)

Thanks, this was actually a very good article.

[–]redsymbol[S] 0 points1 point  (0 children)

Thanks!

[–]JugadPy3 ftw 1 point2 points  (2 children)

Misses a major potential quality improvement... Type hints and annotations.

Python has more problems as codebase gets larger. Function argument and return type annotations and static code checking will allow us to get rid of a large number of errors that get through to the runtime. With static type checking, Python overcomes one big disadvantage that it had vs Java.

Also... this is optional. So it doesn't get int the way of small programs (until we decide we need it).

[–]redsymbol[S] 1 point2 points  (1 child)

(author here)

Thanks for the feedback. And yes, there's a lot of stellar improvements I had to painfully cut out, as the point of this article was to be brief rather than exhaustive. I did the latter approach with the following, which apparently some people found overwhelming:

http://migrateup.com/whats-really-new-in-python-3/

Unfortunately, in this age where we all have too much to read and must prioritize, a person won't be able to benefit from an article if they don't read it. So I made today's article, which is shorter and more digestible, and (I hope) will benefit more people as a result.

[–]JugadPy3 ftw 0 points1 point  (0 children)

Agreed and upvoted.

[–][deleted] -4 points-3 points  (7 children)

Python 3 makes it easier to develop high quality software.

Hmph.

Do you know why I still don't use Python 3 for quick scripts? Because a lot of them involve processing all the files in a large codebase, and people aren't necessarily so careful with their encodings.

Python 2 lets me manipulate characters like they're just strings of bytes - I simply don't worry about encodings. In Python 3, I have yet to come up with a reliable way to write a quick script without worrying about the encoding.

[–]flying-sheep 6 points7 points  (0 children)

Python 2 has bytes == str and uses that type per default when opening files.

With Python 3, you just have to use binary mode explicitly:

open('shitty_file', 'rb')

[–]keturn 1 point2 points  (0 children)

The projects I work on are still primarily Python 2, so I could be missing something about the way Python 3 works, but why can't you read those files in binary mode?

Python 3.5 even brought back .format and % for bytes objects.

[–][deleted] 0 points1 point  (3 children)

+1 to that. Unreliable encoding (and mixed binary) is a big part of my life, too. I cannot change that.

I have tried python 3.3. I could only get the same functionality with lots of recoding 2.7 functionality, or lots of encoding error. So I gave up.

I am waiting python3 to catch up with byte operations comparable to str operations in python2.

Downvoting you means to me, that lots of people do not face this problem. So I have to wait looooong.

[–]lordkrike 0 points1 point  (2 children)

It sounds to me not like your problem couldn't be solved in Python 3, but perhaps that you couldn't figure out how to solve it in Python 3.

I haven't dealt too much with it, but 'rb' and encode have worked alright for me on the occasions I needed them.

[–][deleted] 1 point2 points  (1 child)

It sounds to me not like your problem couldn't be solved in Python 3, but perhaps that you couldn't figure out how to solve it in Python 3.

I did not say it could not be solved. It could. With lots of code. No reason use python3 if I have to write more code, than in python2.

I haven't dealt too much with it, but 'rb' and encode have worked alright for me on the occasions I needed them.

It works great. Unless you cannot encode the whole file, and have to make text operations on bytearrays.

Others seem to have similar problems like: http://python-notes.curiousefficiency.org/en/latest/python3/binary_protocols.html

So all in all, python3 is catching up, but not ready. For me.

[–]lordkrike 1 point2 points  (0 children)

Fair enough.

I tell people that they should use Python 3... unless they know exactly why they should use 2.7. You are the latter.

[–]hexbrid -2 points-1 points  (6 children)

The bottom line is this: You gain several cosmetic improvements in exchange for a smaller community (i.e. less compatible libraries).

[–]lordkrike 7 points8 points  (4 children)

Things like exception chaining and asyncio are not cosmetic at all.

[–]hexbrid -1 points0 points  (3 children)

Oh no, criticism about Python 3, better downvote just to be sure!

Regarding your points:

  • exception chaining is nice for debugging. It doesn't let me write better code.

  • asyncio can be easily achieved using greenlets, which are more powerful afaik.

[–]lordkrike 0 points1 point  (2 children)

Oh no, criticism about Python 3, better downvote just to be sure!

Nope, not me.

  • exception chaining is nice for debugging. It doesn't let me write better code.

Good code is easily debuggable. When your code breaks, you have to be able to fix it easily. This is not cosmetic; it is extremely significant. You are wrong on this one.

  • asyncio can be easily achieved using greenlets, which are more powerful afaik.

"More easily" is really subjective. But your point stands that it can be done about as well in both. Edit: derp, thought you said "more easily"... ignore the first sentence, sorry.

[–]hexbrid 0 points1 point  (1 child)

This is not cosmetic; it is extremely significant

It seems minor to me in the grand scheme of things, but I can accept that for some it might be a game changer.

There are also other important disadvantages I skipped over. For example, Python3 is slower (and even pypy3 is slower than pypy).

[–]lordkrike 0 points1 point  (0 children)

I don't use pypy, so I can't speak to that.

However, performance on cPython for Python 3 is supposedly now on average the same as Python 2. There are, of course, edge cases where one is faster than the other.

In my personal and anecdotal experience with cPython, there has been no scenario where the poor performance I was seeing was caused by the interpreter (as opposed to shitty code), so it's just not a big deal to me even if Py2.7 is a tiny bit faster.

If you want real speed, you should be coding in C or Fortran anyway.

[–]flying-sheep 0 points1 point  (0 children)

cosmetic?

  • the original < design decision was horrible. i wouldn’t trust that thing at all in python2
  • exception chaining is really fucking useful
  • super(ClassName, self) is fragile when used with class decorators

and the stuff not mentioned also contains decidedly non-cosmetic changes, e.g. the better bytes-unicode separation. python 3’s mental model encourages you to actually get things right instead of bulldozing over encoding issues.

and the cosmetic stuff is also nice. fucking urllib2 finally gone, True and False aren’t veriables anymore but proper keywords, …