r/ProgrammingLanguages • • Nov 21 '17
Python 3 and Firefox 57 (an observation)
[deleted] — view deleted post
13
Upvotes
r/ProgrammingLanguages • • Nov 21 '17
[deleted] — view deleted post
View all comments
Show parent comment
9
u/oilshell Nov 22 '17 edited Nov 22 '17
I just looked back on the commit history... I remember having a problem with subprocess, but it looks like I could have done a cleaner job converting from Python 2 to Python 3. I think it would work, but it adds significant friction:
'foo'tob'foo'everywhereopen('foo.txt')toopen('foo.txt', 'rb')everywherecStringIO.StringIO()toio.BytesIO()everywhere. It appears I did make the mistake of sticking toio.StringIO(), and then you still have a lot the mixed-type problems of Python 2, as far as I can tell.I don't think I ran into this, but Python 3 bytestrings were not exactly until Python 3, because they didn't support
%:http://legacy.python.org/dev/peps/pep-0461/
I think I WOULD have run into this had I changed every
'foo'tob'foo'in my program, but I didn't.OH NOW I remember -- this is the crux of the issue -- I used
2to3, and2to3assumes that you want to live in a "unicode string regime", so it does not change every'foo'tob'foo'. But all my programs want to live in the byte string regime (with utf-8 encoding).So 2to3 actually doesn't help you convert, if that's the style your program requires. It encourages the "wrong" style. So I did a sort of half-job converting with
2to3[1], and then everything appeared to work. Then a few weeks or months later, I hit data-dependent uncaught exceptions!I wish that Python 3 would have taken Go's approach and used a utf-8 centric string representation (although I understand why they did not, given Python 2's design). It saves memory, easier to implement (look at the enormous duplication between
stringobject.candunicodeobject.c), and I believe it would work better in a dynamically typed language than the scheme they chose.I think the problem with Python 3 is that it was somewhat of a break, but not enough of a break. All the cleanups that would REALLY be worth it would break too much code. For example, removing all ref counts and globals from the Python/C API. Now THAT would have been really nice, but it would require a big rewrite of almost every extension in existence.
The other two more important reasons I switched back:
mypy(with good annotation syntax). But mypy was completely unsuitable for my metaprogramming-heavy program. mypy turns Python into Java, which is not what I want at all.codeobject.c, which represents bytecode, but I don't remember the exact details.It was probably the same
2to3problem again. This was the straw that made me say "f it" and just go back to Python 2, and use the Python 2 compiler module unchanged.So I'm not sure if I pin the blame squarely on Python 3. But certainly Python 3 is not better for my programs. It was also noticeably slower (as of Python 3.5).
Anyway that was probably more info than you wanted, but Python 2 vs. Python 3 is a good language design comparison, so I have had that in my head for awhile :)
[1] https://github.com/oilshell/oil/commit/06a53a5f775816e9bf2eb4ef4fbe77225dfadd9e#diff-c0be61b9ecd02624103eada0c305c8e9