News for hackers. Stuff that matters.
Re:PEP 505: Bringing None-Aware Operators to Python by catdog on Saturday August 11, 2018 @11:35AM (#17740067)
Not just for beginners, the proposed syntax looks horrible in general. It's moreover already possible to put this into one line:

  libpaths = [] if libpaths is None else libpaths.split(":")
Re:PEP 505: Bringing None-Aware Operators to Python by gaius on Sunday August 12, 2018 @07:31AM (#17743915)
Yes, this PEP looks like it is trying to turn Python into Ruby where the ? suffix is common for a function that returns a bool. Also weird syntactic magic that you can't really figure out, you have to be told about. I wonder if the original author of the PEP is a "rubyist".

Of course in Python [] is False and in Ruby it's true...

Re:PEP 505: Bringing None-Aware Operators to Python by hnra on Sunday August 12, 2018 @08:39AM (#17744092)
Re:PEP 505: Bringing None-Aware Operators to Python by gaius on Sunday August 12, 2018 @08:55AM (#17744143)
operators from C#

Why not go the whole hog then, and do a Option[1] ;-)

[1] https://en.wikipedia.org/wiki/Option_type#F#

Re:PEP 505: Bringing None-Aware Operators to Python by marcosdumay on Sunday August 12, 2018 @10:50AM (#17744580)
What does you gain from optionals if you can't determine types at compile time?
Re:PEP 505: Bringing None-Aware Operators to Python by dragonwriter on Sunday August 12, 2018 @10:54AM (#17744598)
> What does you gain from optionals if you can't determine types at compile time?

As well as type checking (which is relevant because Python has AOT checkers even if they are optional), Options, compared to bills, give you nestability, which is a runtime advantage not dependent on static type checking.

Re:PEP 505: Bringing None-Aware Operators to Python by mmirate on Sunday August 12, 2018 @09:04AM (#17744177)
Option is bubkes if the language itself still has the billion-dollar mistake; that's why F# and Scala are far less practical than OCaml. Python also has it with "None" (though since it is dynamically typed, it's arguable that from the perspective of any given type, every value of every other type is a fresh instance of the billion-dollar mistake).

And sadly, removing None from Python and replacing it by Option - let alone removing Exception and letting Result (aka Either) take its rightful place - would cause huge amount of Python code to need rewriting. And it wouldn't even be worth it because of dynamic typing.

Re:PEP 505: Bringing None-Aware Operators to Python by dragonwriter on Sunday August 12, 2018 @11:37AM (#17744796)
> Yes, this PEP looks like it is trying to turn Python into Ruby where the ? suffix is common for a function that returns a bool.

No, it's nothing like the Ruby convention. It's much more like th C# operators.

Re:PEP 505: Bringing None-Aware Operators to Python by agumonkey on Sunday August 12, 2018 @07:50AM (#17743963)
do people use

    x = x or []
or is it considered non idiomatic in python ?
Re:PEP 505: Bringing None-Aware Operators to Python by tomchristie on Sunday August 12, 2018 @08:00AM (#17743986)
It’s okay-ish. You do need to be careful about what falsey values `x` might be tho, as it could introduce edge-case bugs.

Using `x = [] if x is None else x` is more precise.

Re:PEP 505: Bringing None-Aware Operators to Python by Asooka on Sunday August 12, 2018 @09:16AM (#17744219)
I would really just write `if x is None: x = []`