by bruxis · 6y ago · 0 comments
If the python 3 interpreter could still run python 2 code. If you could mix and match python 2 and 3 code on a per-module, per-file or even per file basis, then the transition could have been so much smoother.
- the languages were not that different, so no need to learn the new version
- python core devs gave 10 years to make the transition. Then extended it.
- it was possible to write code running on python 2 and 3
- python is very expressive, hence the code base have way less numbers of lines than in C++
- python cared only about one implementation, Cpython. The rest of the world needed to follow. Some didn't, like Jython and stackless, and the community didn't blink.
Despite all that, the transition was very painful.
It's just that aghast people are the most vocal. You don't hear the 90% of people that are happy. They don't take the time to speak up. But the unhappy complain all the time.
Utterly pointless and reputationally ruinous. I don't do serious work in Python any more
It would be unwise to design an API that promotes a niche need like dealing with a legacy file system with corrupted file names. This is what Python 3 fixed, making the easy things easy, and the complicated things possible, not the other way around.
But Python 3 is absolutely up to the task of handling legacy file systems with random encoding mixed in, you just need to tell it explicitly you are doing so.
Let's create a file with a completely garbage name, made of random bytes, which is allowed on Unix:
>>> import os, sys
>>> sys.version_info
sys.version_info(major=3, minor=7, micro=5, releaselevel='final', serial=0)
>>> with open(os.urandom(32), 'wb') as f:
... f.write(os.urandom(200))
If you pass bytes to any file system function, it will return file names as bytes: >>> filename = os.listdir(b'.')[0]
>>> type(filename)
<class 'bytes'>
>>> filename[:10]
b'\xf8-U\xa5\x1dq\xad?\xbf\xa2'
And you can just open that: >>> data = open(filename, 'rb').read()
>>> data[:10]
b'E\x05\xce*M \xf5\xfeK\x18'
>>> type(data)
<class 'bytes'>
You do exactly the same as what you did with Python 2, and treat the files as raw bytes entirely, without thinking about the content.Some API in Python require text. If you want to pass the file names to those API, you can use surrogate escape, which let you convert back and forth between arbitrary bytes and utf8 text, without loosing information:
>>> as_text = filename.decode('utf8', errors='surrogateescape')
>>> as_text[:10]
'\udcf8-U\udca5\x1dq\udcad?\udcbf\udca2'
>>> type(as_text)
<class 'str'>
>>> as_text.encode('utf8', errors='surrogateescape') == filename
True
This is a good thing, it forces the dev to be explicit about the places in your code where you are dealing with a specific scenario. It also makes you pay the price of doing so opt in, not opt out.If you have to do a robust version of this with Python 2, you will have to do that anyway: at some point mixed encoding will bite you if you don't have a neutral representation for them. Python 2 gave you the illusion of robustness, because it said "yes" to most operations.
I remember quite well that a lot of Python 2 programs didn't work in Europe because your user directory would contain your name, which could be non ascii. Python 2 programs are opt in to deal with it. It's the opposite philosophy, and caused so many crashes.
We are at Python 3.8.
Python 3 has been around for 13 years, during which Python 2.7 was still supported.
This doesn't match reality. In reality, many Python projects have way more lines of code than equivalent C++ projects. Probably because of the 'expressiveness' you cite; you can't really showcase your love of coding and job security though artificial complexity without 'expressive' bells and whistles. (This is the idea that lead to languages like Go, I'm pretty sure.)
That said, C++ is plenty 'expressive' itself.
That is mathematically impossible. Even if the syntaxes were exactly the same (which they are not, python syntax is on average shorter), the low level nature of C++ requires your code to do operations that Python does need to do, such as memory management.
It's like stating the sky is red.
I'd also argue that operator overloading etc lets C++ be just as expressive as Python, the libraries just need to be designed with that in mind.
The to abandon backwards compatibility in C++ is to make a mockery even of the name of the language (see the "C" in there). If they want to create a new language they should call it something different. Willfully abandoning backwards compatibility and keeping the name is an abuse of one of the great brands in software.
I consider this more a case of the ossification of search.
Neither search engines nor specific sites like Stack Overflow deal with the fact that information can switch from right to wrong with age.