4 ms·
The reasons the transitions worked were that: - the languages were not that different, so no need to learn the new version - python core devs gave 10 years to
by BiteCode_dev 7y ago
The reasons the transitions worked were that:
- 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.
- otabdeveloper2 7y ago> python is very expressive, hence the code base have way less numbers of lines than in C++ 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.
- BiteCode_dev 7y ago> many Python projects have way more lines of code than equivalent C++ projects. 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.
- snovv_crash 7y agoOnce you've written sufficient unit tests to prove your code works as well as a C++ equivalent does just by compiling, I don't think Python ends up being more dense though. 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.
- BiteCode_dev 7y ago> Once you've written sufficient unit tests to prove your code works as well as a C++ equivalent does just by compiling You mean in the same way C++ dev write tests to prove that all their code has no memory error which you get in Python for free ? Except: - tests are way shorter to write in python than in C++ - C++ devs often write zero tests for their code, just like python devs - python duck typing + REPL means compiler checks are rarely necessary - if you need to be type checks, you use type hints in python, which even then is still less verbose than c++ > 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. Ok, let's say you have this json: [{ "name": "Kévin", "age": 23, "hired": "2005-06-03 02:12:33", "emails": ["kevin@foo.com", "kevin@bar.com"] }, { }, { "name": "Joël", "age": 32, "hired": "2003-01-02 12:32:11", "emails": ["joel@foo.com", "joel@bar.com"] }, ... other entries ] It's very simple. Very basic. There is no trick in there: it's standard utf8, well formed, no missing value. You want to print people details in alphabetical order this way: Joël (32) - 02/01/03: - joel@foo.com - joel@bar.com Kévin (23) - 03/06/05: - kevin@foo.com - kevin@bar.com ... other entries This is a 1rst year of college exercise. Nothing remotely complicated. I'm not choosing some fancy machine learning or data processing stuff for which Python has magic libs. Every language can do that easily. In Python 3.7, which is already 2 years old, the code would be: import json import datetime as dt with open("agenda.json") as fd: agenda = sorted(json.load(fd), key=lambda people: people["name"]) for people in agenda: hired = dt.datetime.fromisoformat(people["hired"]) print(f'{people["name"]} ({people["age"]}) - {hired:%d/%m/%y}:') for email in people["emails"]: print(f" - {email}") The entire script is there. There is no trick. This is not a code golf version of of it; I could make it shorter. It really is standard Python. There is no 3rd party lib either. It's not specific to Python, you would get this expressiveness with Ruby or Perl. I don't see in which world you would get that in regular, honest to god, day to day, portable C++. You have to declare types, many includes, you'll have headers and a main function. You have the memory and references to manage. It doesn't make C++ a bad language. It doesn't make python a better language. The C++ version will take way less RAM than the Python version for example. It's just the nature of those languages implies that.
- ComputerGuru 7y ago“Worked?” Nothing about the Python 2 to 3 transition “worked” and people are still aghast that’s Python 2 is being EOL’d.
- slovenlyrobot 7y agoI'm several years into the "upgrade" and find myself still swearing daily at the idiocy of the whole thing. Hundreds of scripts used maybe once a year, such as 'dups.py' I tried to run today, broken by a missing parenthesis, and a function moved around. Utterly pointless and reputationally ruinous. I don't do serious work in Python any more
- joshuamorton 7y agoThat has...nothing to do with python3 though, that's just your broken code being broken.
- jjnoakes 7y agoprint vs print() is what I think the parent comment was referring to.
- slovenlyrobot 7y agoI recognize it may be difficult to understand, but this is a thread about backwards compatibility. Of course if I had any faith in the contemporary Python community, I would still be treating Python as a serious programming language and not be suggesting this is a difficult concept for someone to grasp.
- joshuamorton 7y agoI'm not sure what you're getting at. Perhaps if you could translate to less-smug, the rest of us could understand.
- slovenlyrobot 7y ago
- afiori 7y agofor a long time it was impossible to write code compatible with both python 2 and 3
- BiteCode_dev 7y agoIt started to be possible with Python 3.3, which came out 8 years ago. We are at Python 3.8. Python 3 has been around for 13 years, during which Python 2.7 was still supported.