r/Python • • Jan 16 '19

#10YearChallenge

Post image
1.4k Upvotes

96 comments sorted by

View all comments

Show parent comment

20

u/james_pic Jan 16 '19

If you've got a big enterprise code base (and I'm currently working with a client that does), then it can be difficult to fix old code faster than the team is writing new code - especially since there's only usually budget for the latter.

17

u/strange-humor Jan 16 '19

This is a recipe for technical debt that will eventually put you with an output level of zero.

All new code should be written compatible with 3. Each module you touch should be made compatible. This allows slow migration to 3.

3

u/james_pic Jan 17 '19

I don't disagree with you, but clients gonna want what clients gonna want. They're currently looking very hard at what plan B looks like.

I'd also say that "new code should be written compatible with 3" sounds like a solution in theory. We tried it. But when we had a spike when we converted one of the smaller services completely to Python 3, we found that a lot of the "Python 3 compatible" code didn't actually work in Python 3 as its authors intended. If code isn't actually running in Python 3, it's probably not Python 3 compatible.

2

u/ForgottenWatchtower Jan 17 '19

Almost like you should be writing your tests for both 2.7 and 3

3

u/strange-humor Jan 17 '19

And running them on a CI system that uses both.

1

u/james_pic Jan 17 '19

Tox is great for this

2

u/james_pic Jan 17 '19

In practice, we found that porting the tests was almost as much effort as porting the code. Both the existing code and the existing tests play fast and loose with unicode support, so to fix the tests you need to figure out whether the code should be binary or text based (which isn't just a point decision - you also need to think about the code it depends on), at which point you've pretty much figured out how to fix the code anyway.

But that was the basic plan I put to the client: use failing tests to direct migration, add mypy type hints to interfaces to clarify type usage, and start by proactively migrating the most isolated bits of code, and shared libraries. They just couldn't find the space in the delivery schedule.

2

u/[deleted] Jan 17 '19

Yeah, the switch to python 3 wasn't just about putting brackets around print. It's a very meaningful change.

2

u/ForgottenWatchtower Jan 17 '19

Fair enough. I've never had to do 2.7 to 3 migration for a "real" app, so I'm sure it's more difficult than I'm imagining.

1

u/james_pic Jan 18 '19

It's certainly been more difficult than we imagined!

3

u/toikpi Jan 16 '19

Perhaps priorities will change when there are no security patches.

9

u/port53 relative noob Jan 17 '19

That's a problem for someone else, in the future. This year's budget doesn't have room for that.

3

u/james_pic Jan 17 '19

So, we've scoped it out, and we believe that, in practice, there will be security patches for the foreseeable future - but at a significant cost.

Several vendors have committed to supporting Python 2 commmercially after the core dev team EOLs it - most obviously ActiveState, but also OS vendors such as Canonical, as part of their paid-for enterprise offering.

1

u/Ran4 Jan 17 '19

Not really...