4 ms·
How did a project like Babel not evolve to compile python2 into (horrific code) that runs with python2 compatible semantics on the python3 runtime ...? Is that
by breatheoften 7y ago
How did a project like Babel not evolve to compile python2 into (horrific code) that runs with python2 compatible semantics on the python3 runtime ...? Is that not possible for some reason?
- _bxg1 7y agoThere's this: https://docs.python.org/2/library/2to3.html https://docs.python.org/2/library/2to3.html But the thing with Babel is that it only adds features to JavaScript, it doesn't translate between two disjoint languages. I'd assume that has an effect on its viability as a project.
- nickm12 7y ago2to3 is such a small part of the solution. It only takes care of basic stuff, but to really get things right you need to know the types.
- alangpierce 7y agoPython 2 and 3 are not compatible via syntax translation in the same way that many new JS features can be transpiled to old JS. In Python 3, strings work differently in subtle ways that force you to be more careful, and a source code translator doesn't have any reasonable way to know whether a variable is a string anyway. You also see this sort of thing in JS: Babel never tried to implement Proxy because it really needs runtime support and can't be implemented by syntax translation.
- chubot 7y agoIt’s not possible in general because you can only do a syntactic translation of python. To preserve the meaning of the program you would have to statically know something about the data types used. This is one reason why Dropbox, Facebook, and google have developed their own python type checkers.