3 ms·
> Python 2 to Python 3 may have been a painful transition, but dealing with text in Python 3 is mountains better than beforehand it is not python 2 made a dis
by kragen 3y ago
> Python 2 to Python 3 may have been a painful transition, but dealing with text in Python 3 is mountains better than beforehand
it is not
python 2 made a disastrously wrong choice about how to add unicode support
python 3 inserted that disastrously wrong choice everywhere (though at least you no longer get compile errors when you put a non-ascii character in utf-8 or latin-1 in a comment, a level of brain damage i've never seen from any other language)
rust and golang made reasonable choices about how to handle unicode; python, by contrast, is a bug-prone mess
i've lost python error tracebacks generated by an on-orbit satellite because they contained a non-ascii character and so the attempt to encode them as text generated an encoding error. python's unicode handling catastrophe has made it unusable for any context where reliability is especially important
- amluto 3y agoI would argue that Python 3 reliability issues should be blamed on inadequate static checking, not on Unicode strictness. If you do foo.decode(), you are introducing an operation that can throw. If you are programming in Python for a reliability-critical environment, you should detect this at commit/test time and handle it appropriately. Rust is every bit as Unicode-strict, but it’s harder to fail to notice that you have a failure path. Meanwhile, Python 2 will just happily malfunction and carry on. Sure, the code keeps executing, but this doesn’t mean that you will actually get your error message out.
- kragen 3y agopython has a ubiquitous lack of static checking; every other feature added to it must be considered in that context. if on balance it's bad without static checking, it's bad in python the code in question was not doing foo.decode() or foo.encode(). it was writing a string to a file. python 3 inserts implicit unicode encoding and decoding operations in every access to environment variables, file names, command line arguments, and file contents, unless you pass a special binary flag when you open the file, as if you were on fucking ms-dos. all those things are byte strings, and rust and python 2 give you access to them as byte strings. python 3 instead prefers to insert subtle bugs into your program
- oconnor663 3y agoIt seems like what Python needs here is some equivalent of .to_string_lossy(). But that's just a library function, not a big architectural change.
- capitainenemo 3y agoIt's also made for hard to port python2 code. I have a dozen line python2 script I use regularly that a dozen python experts have thrown up their hands on easily porting to python3 - I'll probably just rework it in something else, like rust (not in the least since I don't want to write it in python anyway). Then there's https://gregoryszorc.com/blog/2020/01/13/mercurial%27s-journey-to-and-reflections-on-python-3/ https://gregoryszorc.com/blog/2020/01/13/mercurial%27s-journ... where he comments that the design choices of python3 forced implementing a large portion of core themselves and that had rust been a bit more mature they probably would just have migrated to that instead.
- selimthegrim 3y agoOk I feel less bad about struggling to port similar length scripts to Python 3 then
- xorcist 3y agoPerl made reasonable choices for unicode. A decade earlier. They are from the same culture and have similar use cases. There was plenty of time to learn.
- Groxx 3y agoPerl is a surprising font of well thought out design decisions. It's not a language I would generally recommend using, but oh boy can you learn a lot of things by learning how to use it.
- Spivak 3y agoHard disagree, there's plenty to complain about with python strings but drawing a formal distinction between str and bytes is one of the smartest things they did for the language. It made the transition from 2->3 a huge PITA but it's one of the things that forces you two write better code. You have to actually acknowledge when you're doing an encoding/decoding step and what encoding you expect. Python3 caught a programming error for you and you're mad about it. The traceback you got was an encoded form (bytes) that you were blinding decoding in ascii when it was in fact UTF-8. You can tell it to truck through with surrogateescape but surely you can agree that it would be insane to make that the default.
- kragen 3y agothis is incorrect, see above
- BobbyTables2 3y agoSounds like you should make friends with latin-1 encoding. All 256 8bit values are valid.
- Const-me 3y ago> or latin-1 in a comment, a level of brain damage i've never seen from any other language I know another one, HLSL – Microsoft’s language widely used to write graphics and compute shaders for Direct3D GPUs.