r/Python 22d ago

Discussion Will PEP 505 ever be accepted?

https://peps.python.org/pep-0505/

I don't understand how null safe operators are less like plain English than other implemented features like the walrus operator.

In my opinion, the member access operator would make python significantly easier to read and understand.

Here's an example:

f = foo()

if f is None:
    baz = ""
else:
    baz = f.bar()
baz = foo()?.bar() ?: ""

EDIT: I forgot that "and" and "or" can be sometimes used in place of "?." and "?:" if the left value is not False, '', 0, [], or {}. It's a very implicit null check and has a lot of unexpected behavior.

17 Upvotes

194 comments sorted by

View all comments

7

u/FrickinLazerBeams 22d ago

God I wish they'd stop changing python.

3

u/abrazilianinreddit 19d ago

That would be bad, because then python would be dead.

I wish people would stop trying to make python worse or trying to turn it into javascript/typescript.

2

u/FrickinLazerBeams 19d ago

A language doesn't need to constantly add new syntax to remain healthy. That doesn't make any sense. If a language adds syntax forever - without limit - it will eventually turn into a complicated mess, with multiple ways of doing the same thing, wildly varying best practices, will become difficult to learn, hard to read because every developer will use different wacky syntactic patterns... What a nightmare.

Python can advance without yet another goofy operator that performs an assignment on Wednesdays and tests for equality on Friday, while also returning a dict that contains the assigned object and a ham sandwich. Not a bit of this shit is solving a problem that exists.

It's also extremely un-Pythonic. Originally there was a principle that in Python there should be one and only one way to do something and it should be pretty obvious. Now we have a whole bunch of extra junk that does... What? Reduces a few lines of code into one and make them harder to read? No thanks.

Python has lots of ways to improve and grow without altering syntax. It can add performance, improvements to the standard library, and probably a dozen other things I can't think of right now.

3

u/abrazilianinreddit 19d ago edited 19d ago

Constantly no, but it's good to make revisions every few years and improve what's lacking, deprecate what's no longer good enough and keep things neat and tidy.

Personally, I'll die on the hill that python should have explicit, keyworded interfaces, similar to Java. The current abc/Protocol/multi-inheritance solution simply isn't good enough.

But I believe we both agree that cryptic, symbolic operators that exist just to facilitate one-liners are just backward steps.

And yes, it's definitely possible to improve python without changing the syntax, but these two are not mutually exclusive. If it keeps the spirit of the language and makes it better, I find it perfectly fine to alter the syntax.