Live data from Hacker News

Show HN: Python-to-Python compiler for some 3.6 features in older versions

github.com

31–40 of 113 posts

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#31

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

Because Python 2.7 is, IMO, a better language than Python 3+, e.g.: - I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1] - I prefer map/reduce/filter to return lists rather than iterable - I prefer dict.keys/values/items to return sets/lists rather than iterables, unless I call dict.iter[keys/values/items]

[deleted]

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#32

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

Because Python 2.7 is, IMO, a better language than Python 3+, e.g.: - I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1] - I prefer map/reduce/filter to return lists rather than iterable - I prefer dict.keys/values/items to return sets/lists rather than iterables, unless I call dict.iter[keys/values/items]

> I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1]

uh, `lambda a,b: a + b` works in 3.6...

> I prefer ... to return lists rather than iterable:

Why? I'm just curious. Iterables are much more flexible than lists, unless you need random access... at which point list(...) works pretty well.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#33

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

Because Python 2.7 is, IMO, a better language than Python 3+, e.g.: - I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1] - I prefer map/reduce/filter to return lists rather than iterable - I prefer dict.keys/values/items to return sets/lists rather than iterables, unless I call dict.iter[keys/values/items]

> I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1]

It already works this way.

    Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> add = lambda a, b: a + b
    >>> add(1, 2)
    3
> I prefer map/reduce/filter to return lists rather than iterable

You can produce a list from any iterable by passing it to `list()`. You cannot take a materialized list and make it lazy though.

> I prefer dict.keys/values/items to return sets/lists rather than iterables, unless I call dict.iter[keys/values/items]

Why? Sets are mutable. What happens when you mutate dict.values? It doesn't make sense.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#34
post #24

I'm confused with the way the "Supported features" section is divided. Does it mean I can only use f''-strings if the target version is 3.5? Why such a limitation?

I think it means that you tell the compiler what version of Python the original source code is in, so it knows how to compile it. So, if your codebase has f''-strings then the compiler needs to know.

That's my guess, anyway.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#35

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

Serious Answer: Because some of us have some rather large perfectly working systems written in 2.7 and using lots of different libraries that moving to 3 is a major project requiring a good amount of time and effort. Not all of us have hobby-sized projects on the go.

Even hobby sized projects can be a major chore. Especially if it's wrapped up in a Gtk transition too.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#36

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

As others pointed out, the cost of moving from 2.7 to 3 may simply be to high. Remember that while much can be done automatically, you still need to test that all your code still behaves as expected afterwards. I was one a project that did migrate a rather large web application and it was pretty painless, but I can easily imagine more complex code bases having issues.

I don't really see the benefit of a Python 3.6 to 2.7 transpiler/compiler though. More realistically I would require that all new code be both 2 and 3 compatible, for when the eventual migration will happen. This isn't necessarily and easy task either, but then you're only depended on the Python project, not some random transpiler that might not see further development.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#37

Serious question: Why would anyone still be doing anything with Python 2.7 except porting the last remnants of their code base to 3.X?

"Why don't you just rewrite it in X?"

Because Python 3.X is not backwards compatible and we have millions of lines of production code in Python 2.X.

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#38
post #24

I'm confused with the way the "Supported features" section is divided. Does it mean I can only use f''-strings if the target version is 3.5? Why such a limitation?

I think it means that you tell the compiler what version of Python the original source code is in, so it knows how to compile it. So, if your codebase has f''-strings then the compiler needs to know. That's my guess, anyway.

[deleted]

Re: Show HN: Python-to-Python compiler for some 3.6 features in older versions

#40

Earlier quoted context omitted.

Because Python 2.7 is, IMO, a better language than Python 3+, e.g.: - I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1] - I prefer map/reduce/filter to return lists rather than iterable - I prefer dict.keys/values/items to return sets/lists rather than iterables, unless I call dict.iter[keys/values/items]

> I like lambda a, b: a + b syntax better than lambda a_b: a_b[0] + a_b[1] It already works this way. Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> add = lambda a, b: a + b >>> add(1, 2) 3 > I prefer map/reduce/filter to return lists rather than iterable You can produce a list from any iterable by pa…

lambda a, b: a + b kind of works, but you can't call it with tuple argument (which you could in Python 2.7). This hurts when e.g. you have a list of pairs and try to map when via lambda, e.g.: map(lambda a, b: a+b, [(1, 2), (3, 4)]). Even worse, this won't fail right away in Python 3 (thanks, lazy evaluation in map), but will raise when you try to use the result of map
Post reply on HN