r/Python • Freelancer. AnyFactor.xyz • Sep 16 '20

News An update on Python 4

Post image
3.3k Upvotes

389 comments sorted by

View all comments

Show parent comments

77

u/panzerex Sep 16 '20

Why was so much breaking necessary to get Python 3?

180

u/orentago Sep 16 '20

Having strings support unicode by default was a big reason. In Python 2 unicode strings had to be prefixed with a u, otherwise they'd be interpreted as ASCII.

0

u/[deleted] Sep 16 '20

[deleted]

82

u/[deleted] Sep 16 '20

I have prod 2.7....talking to logic written in the 90s.

Kill me.

56

u/[deleted] Sep 16 '20 edited Sep 17 '20

Python3 > Datastage > Python2 > Shell (Kornshell) > Perl written in '99 across servers.

I'll have one kill please.

7

u/clawjelly Sep 17 '20

Nuke it from orbit. It's the only way to be sure.

→ More replies (5)

8

u/MiscWalrus Sep 17 '20

It's not like the rules of logic changed since the 90s. You could do a lot worse than having to support python 2.7.

11

u/lzantal Sep 17 '20

Still maintaining one in production with Python 2.4 and Django 1.3 🙄😬

→ More replies (8)
→ More replies (3)

47

u/[deleted] Sep 16 '20

That was just ascii for trouble imho.

15

u/toyg Sep 16 '20

This joke was not hard to decode correctly.

8

u/BruceJi Sep 17 '20

A pun thread? Don't byte off more than you can chew!

→ More replies (4)
→ More replies (3)

73

u/flying-sheep Sep 16 '20

Because they changed a core datastructure. str used to be what bytes is today, but it also predated unicode (today called str). Therefore the bytes type was used for text and binary APIs.

When fixing all this, they had to break a lot of core APIs that used to accept bytes and today sensibly only accepts the unicode str.

And because of that huge change they also took the opportunity to change a few other idiosyncrasies.

My only gripe: One additional thing they should have changed is that {} should be the empty set and {:} should be the empty dict.

21

u/miggaz_elquez Sep 16 '20

you can write {*()} to have an empty set if you want

32

u/crossroads1112 Sep 16 '20

Thanks I hate it.

26

u/Brainix Sep 17 '20

My favorite thing about {*()} is that you don't even save any characters over typing set(). 😂

→ More replies (1)
→ More replies (10)

33

u/irrelevantPseudonym Sep 16 '20

My only gripe: One additional thing they should have changed is that {} should be the empty set and {:} should be the empty dict.

Not sure I agree with that. It's awkward that you can't have a literal empty set, but having {:} would be inconsistent and a special case that (I think) would be worse than set().

0

u/[deleted] Sep 16 '20

[deleted]

12

u/hillgod Sep 16 '20

It's definitely not an anti-pattern, and, in fact, the literals perform faster.

→ More replies (12)
→ More replies (6)

8

u/james_pic Sep 16 '20

Perhaps surprisingly (given what we know now about the migration process), the switch to unicode strings wasn't expected to be a big deal (it didn't even get its own PEP, and was included in a PEP of small changes for Python 3 - PEP 3100), and the other changes were seen as more break-y.

→ More replies (3)
→ More replies (7)

23

u/[deleted] Sep 16 '20

Python 3 was not backwards compatible with 2, so companies and package creators alike were initially hesitant to make the switch so as to not break things. There also weren’t many, if any, tools to help port things over.

The lack of backwards compatibility was done on purpose because part of their goal was to remove clutter and make things more intuitive/easier to use (e.g. print changed from a statement to a function).

12

u/DiggV4Sucks Sep 16 '20

I've only made two unassailable (so far) decisions in my career. The first was to support MFC instead of OWL for Windows development.

The second was to target Python 3 for my current company's testing efforts. We were even able to convince a medium sized tool vendor to support both Python 2 and Python 3 from their original decision to support only Python 2.

→ More replies (4)

13

u/gregy521 Sep 16 '20

It was designed to rectify fundamental design flaws in the language—the changes required could not be implemented while retaining full backwards compatibility with the 2.x series, which necessitated a new major version number. The guiding principle of Python 3 was: "reduce feature duplication by removing old ways of doing things".

Here's a short list of some of the key changes. The most obvious of which is the change where '/' represents true division instead of floor division. Some other changes exist, print is now a function, not a statement. You also get iterator objects instead of lists, which is much better for memory management (many pieces of code rely on iterators because the full set of possible options doesn't fit in memory). True, False, and None are also now protected terms which can't be reassigned.

15

u/daturkel Sep 16 '20

Part of any long-term tech project is continuous refactoring. Early on you make certain design decisions which later become an obstacle when trying to expand a feature, so you rewrite early stuff in order to make it more flexible for your new needs.

Often those rewrites are done in ways such that the end user does not need to adapt their behavior (or in the case of a programming language, does not need to change their code). This is the ideal experience for the end user but can also constrain the types of changes that can be made.

Sometimes you realize that the original way of doing things was worse and that it would be creating more difficulty for future development to maintain compatibility, so breaking changes are introduced.

4

u/[deleted] Sep 16 '20

the biggest issue was that python before 3 was mixing string with bytes. This is fine if you use encoding that covers 256 characters, but most of Python 2 code would break when receiving and unicode input.

Python 3 became strict, and those two have separate types, and you need explicitly encode/decode string into/from bytes.

This required to fix your python 2 code (ironically if you didn't use unicode type in python 2 chances are you had less to fix).

Since the unicode part was breaking things, Guido also decided to use that opportunity to clean up some warts in python which contributed further.

→ More replies (10)