3 ms·
The Python developers original plan for the new text model of Python 3 was an expansion of the text model introduced a bit into Python 2. Python 2 has two types
by Jasper_ 5y ago
The Python developers original plan for the new text model of Python 3 was an expansion of the text model introduced a bit into Python 2. Python 2 has two types: str and unicode. str is a sequence of bytes, and unicode is a sequence of Unicode code points. An unfortunate model, but an understandable one. The difficult part was that since unicode was introduced into Python 2 some time after 2.0, they needed backwards compatibility with existing code, and thus decided that any time an operation wanted unicode and received str, the runtime would automatically decode from str to unicode, and vice versa. This implicit decode/encode became a large hassle, so the aim of Python 3 was to remove it.
Unfortunately, while the developers removed the implicit encode/decode in Python 3, they also made the gulf between str and unicode (now called bytes and str) much larger, removing large swaths of useful functionality from bytes, and doubling down on the Unicode code points nature of the new unicode type, despite it being very apparent by then that this was not a good text model to base a language on anymore.
Backwards compatibility was a large issue indeed, but IMO they broke backwards compatibility all to introduce a subpar stricter text model that delivered on far fewer promises than tney were hoping, and in my opinion is worse than Python 2's text model. A more reasonable approach can be found in other languages, which allow iterating over sequences of byte strings by iterating on the fly. Swift, Rust and Go all get this more correct.