r/programming • • Jun 27 '18

Python 3.7.0 released

https://www.python.org/downloads/release/python-370/
2.0k Upvotes

383 comments sorted by

View all comments

114

u/[deleted] Jun 28 '18

I wish I could use it, but so many APIs and software packages my company uses are still on 2.7 ...

0

u/[deleted] Jun 28 '18

[deleted]

66

u/[deleted] Jun 28 '18

Yes really. Mine too. Companies have a lot of old code and there's not much incentive to upgrade it to Python 3 for basically zero benefit.

Actually, it's a big risk because these scripts are generally "tested" by using them and reporting bugs. Upgrade to Python 3 and due to its dynamic typing you're probably going to introduce a load of bugs.

Also I have noticed even some big new projects, e.g. Tensorflow, target Python 2 first and then add Python 3 support later.

The idea that the 2/3 mess is over is unfortunately not true.

31

u/vivainio Jun 28 '18

The "zero benefit" is not true anymore

20

u/peeves91 Jun 28 '18

The old motto "if it ain't broke don't fix it" is applied heavily here.

71

u/[deleted] Jun 28 '18

It kind of is, if the code works fine and isn't being updated, which is the case for a lot of corporate code.

1

u/anacrolix Jun 28 '18

Example?

4

u/1wd Jun 29 '18

One project at Facebook:

... simply ran 2to3 on the code and fixed a few things that it complained about. When they ran the resulting code, they found it was 40% faster and used half the memory.

1

u/anacrolix Jun 29 '18

Sounds like they were abusing range() or something.

2

u/vivainio Jun 28 '18

Types and asyncio come to mind first

4

u/13steinj Jun 28 '18

Types aren't beneficial to every developer. Asyncio has severe usability issues, I'd rather use gevent in an async manner.

4

u/vivainio Jun 28 '18

Ok, f-strings then?

2

u/13steinj Jun 28 '18

While I like them, their only benefit is reducing a call of "string with idens".format(explicits_for_idens) to f"string with explicits for idens", it's syntactic sugar that saves you ".", "ormat", and the parenthesis, nothing more. And it introduces backwards incompatible in minor version numbers, which it really shouldnt.

4

u/somebodddy Jun 29 '18

it's syntactic sugar that saves you ".", "ormat", and the parenthesis, nothing more

I disagree. The greatest benefit of f-strings is that the save you the need to zip the values in your head. Consider this:

'a={} x={} u={} z={} y={}'.format(a, x, u, y, z)

You need to make sure that the list of {}s matches the format arguments. Compare to this:

f'a={a} x={x} u={u} z={y} y={z}'

Now that each expression is written in the place it is supposed to be formatted, we can clearly see that I've "accidentally" mixed y and z. The same mistake exists in the .format() version, but much harder to notice.

In order to avoid that, we can do this:

 'a={a} x={x} u={u} z={z} y={y}'.format(a=a, x=x, u=u=, z=z, y=y)

But now we have to write each variable 3 times.

Of course, this can be solved with .format(**locals()) (or .format_map(locals())). Expect...

a = 1

def foo():
    b = 2
    print('{a}, {b}'.format(**locals()))

foo()

{a} is not a local variable... Luckily, we can use .format(**locals(), **globals())! But then:

a = 1
b = 2

def foo():
    b = 2
    print('{a}, {b}'.format(**locals(), **globals()))

foo()

Now b appears in the argument list multiple times...

And it introduces backwards incompatible in minor version numbers, which it really shouldnt.

What backwards incompatibility? f'...' is a syntax error in older versions of Python, so it shouldn't break older code. Or am I missing something?

→ More replies (0)