A couple years ago, if you asked about Python 2 vs Python 3, everybody would tell you to stick with Python 2...

A couple years ago, if you asked about Python 2 vs Python 3, everybody would tell you to stick with Python 2.7 because that was the most widely supported.

What's the case these days? At work, all our production machines run Python 2.7, so I need to keep writing that no matter what. But is it worth it to spend time learning Python 3? What are the advantages, really?

Other urls found in this thread:

speed.python.org/comparison/,
twitter.com/NSFWRedditVideo

P2's about ready to stop getting support and already isn't getting any kind of new features, performance improvement, etc. The language is literally deprecated and you'd do well to start dealing with some of the syntax and logic changes.

>inb4 butthurt java/C/lisp/hasklel fanboys

i dont give a fuck ill stick on python 2 forever and fucking bank out punch out code fro wheover the fucks needs it and ill make my money taht was fuck off you dicker

Python 2 is just used for the one or two legacy applications that didn't get ported like supervisor.
Most libraries run on 3, RHEL is ready to default to 3 by next version.

>Most libraries run on 3

Is third party library support a big reason for switching to 3? Those production servers at work deal with incredibly sensitive data and I can't use any third party libraries. I write my own for most things. Considering this, is 3 still worth it? What is the point of the syntax changes?

For starters urllib stopped being a mess in py3, you no longer have to deal with urllib/urllib2 and the requests part has been nicely split into urllib.request.
3.6 has f-strings which is the one true solution to stop "doing %s" % ("this") "or {}".format("this"). You get f"x = {x}" instead. Also you can type annotate your functions so you stop having to put that in doc instead. This pretty much explains itself:
def format_date(date: datetime) -> str:
return date.strftime("%d-%m-%y")
There's a lot of nicer stuff, check the docs.

>if I don't use 3rd party modules should I still upgrade to python 3?

Yes dude. Python 3 has been out for 10 years now. That's 10 years of performance improvements and new features. Literally a decade, and you know a decade in tech years is like 100 years for humans.

If you're writing brand new code and have no 3rd party dependencies, you would be a fool to use a legacy, near end-of-life (2020) coding language.

>If you're writing brand new code and have no 3rd party dependencies, you would be a fool to use a legacy, near end-of-life (2020) coding language.
Well, like I said, the machines only run 2.7 so I gotta. But this is good info. Thanks!

I do like dem type annotations...

To add to this, the type annotations are completely optional and do nothing more than provide visual cues for someone reading the code. They have no effect on performance, as if they don't exist at all

Python 3 is still slower than python 2 lol.

>out for nearly 10 (ten) years
>people STILL use 2.7 for projects other than maintaining legacy code

Ah sorry I missed that part. So you aren't allowed to use Python 3? Are you in a government job or something?

Y'all better get yo shit together because like I said, end-of-life for Python 2 is in a couple years and after that you're on your own. No more security fixes, no nothing.

I suspect there are lots of 0 days for Python 2 that will be revealed around that time because the "bad guys" know how many programmers/companies have sat idly by for the past 10 years instead of doing what they should have been -- updating their software.

>talking about Python performance
It isn't and was never intended to be a performance language my dude. If you're interested in performance (sounds like you are), then you should try C or C++

...oh. Fuck that then.

>Are you in a government job or something?

Not quite, but it's a huge movie studio in Hollywood. We're dealing with rough cuts of unreleased features, dailies, etc. We have engineers in our department, but corporate IT rules them all, and has lots of blanket security restrictions in place.

For what it's worth, these servers are not connected to any wide area networks.

Then user shouldn't be talking about (fictitious) 2->3 performance improvements.

>but corporate IT rules them all
tell them to stop using legacy code lol they've had ten years with their thumb up their butts

Ok thanks dude I'll let the Fortune 500 company know

Someone has to because they are completely incompetent from the sound of things. Make sure you make this face when telling them too

Oh no their on premise render farm won't be using python3!

>Y'all better get yo shit together
Python 3 changed so many common syntaxes that migrating from 2.7 to 3 is a massive fucking undertaking, they're honestly better off staying on the same version and maintaining.

>Python 3 changed so many common syntaxes that migrating from 2.7 to 3 is a massive fucking undertaking

A lot of them can be automated, but yeah. It's still a lot of work. Especially if you've written poorly documented spaghetti code.

>they're honestly better off staying on the same version and maintaining
I dunno if I agree with this but I guess that's the bs of the coroproate world. End-of-life software (Python2 and WindowsXP) are infintely maintained because companies just can't make the transitions. If 10 years isn't enough time to update your software, then they should be left in the dust and like you said left alone to maintaine their legacy code in their own little bubble.

It isn't though.
Take a look at speed.python.org/comparison/, most benchmarks that matter (not float e.g.) are in favor of Python 3.
Not that it doesn't mean that Python would be not slow now.

>I guess that's the bs of the coroproate world
Its more like once you have a sufficiently large enough codebase, it becomes prohibitively expensive to update or migrate it. It's the main reason you can still get jobs programming in COBOL and Perl, languages that are either completely dead or have basically been usurped. There's a whole shitload of stuff that still uses them, and it's a lot more reasonable to just keep writing in them than it is to try and convert everything.

Also performance pertains to more than just speed. Dictionaries in Python3.6 take up significanly less memory compared to dicts in 2.7. I can't remember off the top off my head but it's like a 70% saving.

As said already in the thread, 10 years of performance improvements, yet delusional people like call them "fictitious" lmao. Da Nile isn't just as river in Egypt

>it becomes prohibitively expensive to update or migrate it.
This is what I meant by saying "the coroprate world". AKA not wanting to spend money is what causes these companies to continue using legacy software for decades past their expiration date

It's not even just raw dollars to spend on peoples salaries that are doing it, the amount of man hours it takes means no new development happens and the company grinds to a halt. Plus the enormous technical cost of retesting the whole thing to make sure new bugs popped up.

Because it's not worth the cost.
What real benefit would there be?

Clearly I've never dealt with a code base the scale you have, so I just can't wrap my head around why it's such a big deal. If the code is well written, and documented, and has unit tests, then updating it to Python 3 isn't that big of a deal. It really isn't.

I think the disconnect here is that, more than likely, they've got a lot of spaghetti code going on, which makes things much harder than they should be. And in that case I can see how trying to make things work would be hard, especially with employees coming and going over the years.

Not even the biggest ENTERPRISE operating systems give you support past 10 years. I'm talking about RHEL, AIX, Windows Server which are costly horrors to migrate.
The only exception is SAP given that you went through EHP upgrades, and even then they have been pushing migrations to S4/HANA for a while.

You're thinking like a businessman and I"m thinking like a developer, lol. The benefit is that you're not using a deprecated, legacy coding language that's possibly vulnerable to unpatchable 0 days.

I guess that's a risk/cost thing. What are the odds we'll be hacked for using old shit vs what would it cost to update

you've obviously haven't dealt with urllib much, they reorganized the modules but it's still fucking disgusting code that still can't do keep-alive that you'd still be a moron to use over requests

>and I"m thinking like a developer
You're really not, no developer that has been at it for more than a year would want to rewrite the entire codebase from scratch just to upgrade to a newer version of the language.

>more than likely, they've got a lot of spaghetti code going on
Nope, most of it is extremely well written. It's just a VERY lengthy process, and nobody wants to spend the time doing that for such a minimal benefit.
You're really underestimating the time cost, raw dollar cost, loss of productivity and new development, and unfathomably big job of retesting everything. On top of that, you might have to completely rebuild the automated testing database as well as unit testing.
Updating languages to one that isn't backwards compatible is obscenely expensive.

Migrating software platforms is much much cheaper than trying to update your entire codebase.

SAP has its own proprietary language for custom behavior and it broke the whole API in S4.
Reimplementing all the Z objects in a billion+ dollar company is not trivial at all. You could say it's like migrating a shitton of COBOL.

Why is Python 2 backward compatible with Python 1, but Python 3 isn't backward compatible with Python 2?

o lawd what kind of autist nest have i rumbled

>Python doesn't have any kind of goto
Fuck this

I'm reminded of when W3C wanted to switch from HTML to XHTML, for reasons that weren't very clear. Why did they want to switch, anyway? I never saw a clear explanation of that.

I always liked that. It was much more strict of a DOM. An effort to put an end to sloppy markup and improve cross-browser compatibility.

Remember in the mid-90s when a lot of sites would say "Select your browser" and they would have separate sites for IE and Netscape? XHTML was largely to thank for the end of that.

9/10 would buy
Needs a black model

use perl5 instead

Python2 is still the way to go.

I need that phone!

>I can't use any third party libraries. I write my own for most things. Considering this, is 3 still worth it? What is the point of the syntax changes?

There's in my opinion better consistency in 3. If you write sensitive production code, type annotations are your friend.
If you wrote it all yourself, chances are that migrating to 3 will be smooth, and you just add py3-specific stuff the next time the software is reviewed. I also work with python professionally, and there's really hardly anything that really needed changing, the backward compatibility is, despite not being totally complete, pretty good.

If your machines run python2, I'd just check your lifetime analysis and start running python3 on newer machines. If your DTAP cycle is sound this should give little problems. We do the same here: if we need older code on a new server it gets a 2to3 pass, then its manually corrected/optimised before it goes into testing.

Advantages I encounter most:
- Much better stdlib
- More efficient file descriptors
- Improved safety for kwargs, comparisons
- Generators are comfy
- Type hinting is really comfy (for production code)

And most of all
- Asyncio is extremely mega powerful. It's also insanely complicated at this point, but if it improves Python gets go-like scaling/performance

>wanting/needing goto anytime anywhere

Why don't they just consider them different languages like perl 5 and 6? They have clearly failed to make a proper switch to python 3.

>not writing every loop using goto

Because they aren't. Unlike Perl6. Why the heck they even named it Perl?

f-strings are an absolutely retarded idea. Arbitrary expressions mean that it's either impossible or unsafe to use them as anything else than inline literals, it doesn't solve you much typing, it fucks with code parsing and highlighting since you don't expect code inside a string to be semantically meaningful and having a declaration implicitly call arbitrary code is retarded.

Good post user

goto is unironically a good choice when you have to do some common stuff like cleaning stuff up and freeing memory before exiting a function.
In 95% of cases it's better not to use it, but there is that 5% where it's much better and cleaner to use a simple goto rather than splitting a simple 10-line function in 4 small helper functions.
Just because Dijkstra said it's evil doesn't mean it must never be used. SOMETIMES, and I repeat, SOMETIMES, it's a good idea.
The Linux kernel itself uses goto here and there.

Enjoy dragging the language backwards.