Live data from Hacker News

Why I'm Making Python 2.8

naftaliharris.com

311–320 of 392 posts

Re: Why I'm Making Python 2.8

#311

Earlier quoted context omitted.

with open('some latin-1 file', 'rb) as f: text = f.read().decode('latin-1') with open('some utf8 file', 'wb') as f: f.write(text.encode('utf-8')) Python 3's string encoding support is super good. I've said it before and I'll say it again: if you use bytes as a string you are Doing It Wrong. If you use bytes as a string you are Doing It Wrong. If you use bytes as a string you are Doing It Wrong.

And what happens when you don't get a choice about what strings you are digesting?

I don't follow. What do you mean?

To be perfectly clear: bytes (b'') is not a string. Again: bytes is NOT a string. It is an array of octets, aka bytes, aka unsigned 8 bit integers. NOT characters. NOT a string.

If you are dealing with bytes that are encoded representations of a string, then you have to know what encoding they use to decode them and treat them as strings.

Re: Why I'm Making Python 2.8

#312
post #290

Earlier quoted context omitted.

There are numerous metrics out there showing that Python 2.7 is far more ubiquitous than 3.x Here is one recent one: http://www.randalolson.com/2016/09/03/python-2-7-still-reign... If you have counter statistics showing that Python 3.x is more popular than 2.7 I would very much like to see them.

Nice to break down FIVE 3.x versions vs TWO 2.x versions. Stack them up and let's count again.

I agree, I also wish he would give actual numbers, rather than points on log chart, which are very hard to estimate by eye.

But to be fair, even with that, I doubt you would get more than 30% of Python 3 users. Which is kinda in line with other surveys, such as the one from JetBrains. (It's probably a good guess that users of Python applications are even more conservative in upgrading than developers of Python applications.)

Re: Why I'm Making Python 2.8

#313
post #72

Earlier quoted context omitted.

Python 3 fixes no fundamental issues with python 2 and introduced far more warts than it removed. GIL is still there, crummy runtime is still there and unicode is now an even greater mess. I really wonder how many people who bang on about unicode actually have a good grasp of unicode and text processing because python3's unicode design is obviously terrible. I can now access or count code points in O(1) (neither of w…

> I can now access or count code points in O(1) (neither of which is in any way useful) Oh, yeah, I agree that Python's unicode model isn't great. I like Ruby's, and Swift has it's own cool thing going where it's very explicit about the uselessness of code points. However, I think that Python 3 having some form of default unicode support is way better than what Python 2 had. It could be improved (backwards-compatibly…

In all seriousness, I'd much rather python3 had kept str, phased out the unicode type altogether, got rid of all the harebrained locale crap (sys.{get,set}defaultencoding etc) and just provided tooling (collation, regexp, denormalization etc.) for working with utf-8 encoded byte-'str's. This would probably have been a much smoother transition and ended up with a vastly superior result.

I'm pretty sure the people complaining here about how python2 str only supports ascii and they couldn't paste their smartquotes were bitten either by windows or unnecessarily bad unicode/str interactions due to python not just hardcoding utf-8 auto-conversion. That is the only sane thing to do (Your locale isn't *.UTF-8? Well sucks to be you. By now even the Japanese and Chinese seem to slowly have come around to the utf-8 bandwagon, and they had better reasons then most).

I might be wrong, but I can see basically 3 non-idiotic ways to do text in a programming language:

1. arrays of utf-8 bytes (Rust, Go). Python was close to that already and then messed it up. Indexing indexes into bytes O(1).

Upsides:

- efficient: most text you're going to get is already utf-8 and the rest should be converted on ingress/egress; html/css/most code will be represented fairly efficiently even if the body text is mostly say, Chinese; you can do a lot of text processing by just working on the ascii range (e.g. CSV parsing).

- sane: no BOM, no 32 bit encoding of 21 bit quantities etc; unix-compatible

Downsides: - can't efficiently access individual logical characters or know the fixed-font width of the text

- normalization is kinda nasty (concatenation etc.), in practice people just tend to ignore that

- hard to constrain to only valid utf-8 without significant downsides

- maybe not that beginner friendly

2. use some non-array type that doesn't allow for indexing (e.g. ropes), probably using (mostly) utf-8 for internal encoding.

3. arrays of logical characters. That means you need to make up fake characters to handle graphemes that are not directly representable as a single pre-composed code point in unicode. The upside is that this has beginner friendly semantics in a sense and allows indexing on what's meaningful in the domain (graphemes). The downside is that I can't see how to do this with a lot of complexity and some nasty gotchas. This seems to be what perl6 does https://design.perl6.org/S15.html#NFG

Re: Why I'm Making Python 2.8

#314

Earlier quoted context omitted.

with open('some latin-1 file', 'rb) as f: text = f.read().decode('latin-1') with open('some utf8 file', 'wb') as f: f.write(text.encode('utf-8')) Python 3's string encoding support is super good. I've said it before and I'll say it again: if you use bytes as a string you are Doing It Wrong. If you use bytes as a string you are Doing It Wrong. If you use bytes as a string you are Doing It Wrong.

And what happens when you don't get a choice about what strings you are digesting?

I'm not sure what you mean. If you don't know what the encoding of the input file is you have a problem. As far as I know there are libraries to guess the encoding, but it cannot be determined completely accurate.

Re: Why I'm Making Python 2.8

#315
Slightly tangential, but: I've noticed an interesting parallel between the 2.7 / 3.x partisan divide, and the US political partisan divide. In both cases, as partisan passions have increased without relief, there's both A) an increasing unwillingness to agree on basic facts about reality essential to the debate, and B) increasing presumptions of bad faith on the part of their opponents.

Examples of A in this discussion:

- Disagreements about the degree of library support for 3.x

- '' the ease/value of porting from 2 to 3

- '' the rate of industry adoption of 3 for new projects

- '' the degree to which people are driven away from Python entirely because of the version situation

Examples of B in this discussion:

- Claims of paternalism on the part of GVR/ the PSF in pushing 3

- Claims of unreasonable/emotional attachment to 2 by partisan devs

- Claims of willful distortion of facts by both sides (see A)

- Claims that the writing is on the wall for 2, because usage of 3 is supposedly accelerating

- Claims that the writing is on the wall for 3, because it's supposedly taken too long to drive not enough adoption

It seems outrageous to suggest that the differences between 2 and 3 are anywhere near as significant as the differences between, say political conservatism and liberalism, and yet the level of partisanship seems nearly the same. How did it come to be like this?

Re: Why I'm Making Python 2.8

#316
post #244

Earlier quoted context omitted.

There's no controversial changes in python3? Except if you consider print() controversial but that's so silly it's laughable. There are however non backwards compatible changes , like unicode by default, IE7 was also non backwards compatible so the comparision still holds. (with the exception that IE had a compatibility mode if you sent some magic http headers)

It can be silly, but that was one of the reason I picked Ruby over Python 5 years ago for a project. I felt at the time, Python is awesome, however they are taking a weird path.

Do you still feel that way or anything changed?

Re: Why I'm Making Python 2.8

#317
post #21

I can't fault a single thing in his justification. This should have been the approach to modernising python all along.

This approach could not have worked for modernizing python. The whole point of the Python 3 thing was to be able to remove warts in the language that could not have been fixed without breaking backwards compatibility. One core part of this is unicode support -- Python had a horrible story for international text before this. The fact that there are some parts of "modern" Python which could have been implemented in Pyt…

It's super-sad that "Unicode" is a prominent stated motivation for Python 3.

Unicode in Python 2 was fundamentally broken in that whether it had UTF-16 semantics or UTF-32 semantic depended on how the interpreter was compiled. That's a terrible, terrible idea. However, they could have fixed it by sticking to one option: UTF-16 (which provided compatibility with some interesting things that Python interoperated with like Cocoa and, via Jython, Java).

UTF-16 is a sad legacy mistake, but APIs providing Unicode operations of any kind can be build on top. So UTF-16 is a mistake to begin with, but it's not a blocker for supporting all of Unicode and features targeted at the needs of all writing systems and languages. Java, Windows, the Web Platform (including JS) show that proper i18n can be built on top of the bad but backward-compatible 16-bit code unit foundation.

Now, the _even_ sadder part of Python 3 is that if you decide that UTF-16 is a mistake and want to fix it, UTF-32 is the naive and wrong solution. When a Unicode newbie is told about surrogates, they think that UTF-32 is the answer. But then they waste memory and cache line space (and, if dynamically omitting leading zeros on a per-string basis, the compute and copy cost of promoting to different unit width when adding one emoji). And once the damage is done, someone points out that grapheme clusters are a thing, so they still didn't get O(1) indexing to user-perceived units.

The enlightened thing, of course, is to do what Rust does: use UTF-8 and use iterators on top for accessing pieces larger than a code unit (code point, grapheme cluster). (To my taste, Swift strings are too magic and DWIM-y. At least back when I read the Swift book, it didn't even explain the underlying representation. With Rust, the representation is very explicitly known.)

"UTF-16 sucks" is what Python 3 got right. That UTF-32 (with dynamic leading zero omission on a per-string basis) is the answer is what Python 3 got very, very wrong. The correct answers are either UTF-8 (for a new language like Rust) or holding the nose and making stuff work on top UTF-16 (Java, JavaScript) without breaking old programs.

Re: Why I'm Making Python 2.8

#318

Earlier quoted context omitted.

I think after 5 years we should came to the realization that Python 3.x is not the future of Python. You can't blame people to try to find solution.

Except it kinda is the current version to lots of us. I moved to Python as a hobbyist from .net languages and loved the freedom of not having an IDE and working with Linux. The first decent book I read was on Python 3 so I learned Python 3. Lots of us 'newcomers' (not so new in my case) learnt on Python 3, find perfectly good library support in Python 3. In fact the 'old guard', sound a bit like my Dad talking about…

The fact that there's a huge split in the community over the issue shows just how divisive Python 3 is. That said, 3 > 2 in version number doesn't make it better or more "current" (and I've seen a number of projects where the "latest" version wasn't even the latest - it was often an experimental). Yes, you could do just about everything you need to in Python 3 that you can do in Python 2, except that it can be much more difficult depending on what you're doing. e.g. this guy -> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/

I found it's easy enough to add the line:

# -- coding: utf-8 --

to the top of my Python 2 files so I can get UTF-8. That, and Python 2 has the bindings for GTK (which I like to use). Both versions of the language have their usage, and to each his own. There's no sense in bickering about it.

Re: Why I'm Making Python 2.8

#319
post #271

Earlier quoted context omitted.

That's probably true, but unicode_literals isn't the right tool to make an incremental port, because it neither obeys good py2 nor py3 text handling conventions. It would become a substantial detour and end up being a kit more total work. Also, porting can be done in parallel to normal dev. You aim your port at a specific release while you continue fixing bugs. When the port is done, you port over all the patches. Re…

Isn't it as simple as a) do proper string handling in py2 unicode and b) if you write more u"" in a file than "", flip the switch and write "" and b"" instead?

Not quite, because the py2 library is often not compatible with unicode literals, and also because if you flip the switch in a module it changes the API of any functions that returned strings. That might break calling code from other modules.

So then you might have to add code to work around these issues, code that is needed in neither pure py2 or pure py3 -- hence making it a weird detour.

In general, it is more compelling to use `unicode_literals` when back-porting new or existing Python 3 code to Python 2/3 than when porting existing Python 2 code to 2/3 [1]

[1] http://python-future.org/unicode_literals.html

Re: Why I'm Making Python 2.8

#320
post #307
post #33

> And the majority of Python code written does not run under any of the 3.x interpreters. This makes it harder for its users to be productive. What a load of bollocks. For new projects this only matters if libraries aren't ported, which they are for the most part. For old projects, either you're in a situation where you can spend time porting your code to Python 3, or you don't; but as TFA mentioned pep-404, the writ…

(Replying to the top-ranked comment so that as many people as possible see it) While I wish Naftali well in his efforts - I have a private Python-derived language myself! - this is not "Python 2.8." For trademark purposes, "Python" is only what is released or endorsed by the PSF. We have already reached out to Naftali and asked him to change the name of his project and update this blog post accordingly. Obviously, th…

"I don't mind renaming this project. Any other suggestions for good names? I personally like "Pythonesque (/usr/bin/pesque)" the best so far, thanks @dbohdan! :-)"

  - The Author (who isn't me)
    https://github.com/naftaliharris/python2.8/issues/47#issuecomment-266240525
Post reply on HN