We could argue about how intuitive or not these operators are, but they are used in other languages, so they clearly aren't completely unintuitive.
Other languages are other languages. Other languages use the "<condition> ? <expr_a> : <expr_b>" form of the the ternary operator. That doesn't mean we should adopt that into Python.
Being visually obtrusive would help a great deal. Unfortunately I don't think it is visually obtrusive in the ?. and ?[] operators.
My argument about visual obtrusiveness is in the context of me claiming that python attempts to mimic natural language to achieve readability, others countering that `
person.name` is not how periods are used in natural languages, so using other symbols in unintuitive ways is perfectly fine. My point is that '.' is unobtrusive, so it's not *that* different from `person name' which isn't *that* different from `person's name`. The '?' symbol is most definitely more visually obtrusive than a simple '.' because it takes up more space.
We could conceivably have a dunder method that None implemented as returning the other argument and object implemented as returning itself. I'm not really convinced that it's worth it, though.
Yes, I thought of that and came to the same conclusion. It's my understanding that None may not be an actual object, but a special memory location. I'm not sure though and didn't look it up.
Really? Quick straw poll: how often do people care how in-place operators are implemented?
The point I was trying to make is that it doesn't behave or compose like other expressions.As you said, "?" is not an operator, so "a?.b" clearly can't break down into "a? .b".
The problem is that '.' IS a stand-alone operator, so it's natural to visually parse `<expr>.b` as `<expr> .b`, but adding '?.' causes double takes, more mental load, general interruption of the flow of reading. It also sets up the later discussion of other possible uses of the '?' symbol that may or may not have more merit.
Um. How is that supposed to parse? "person[0]" has already been evaluated by the time the "?" operator gets anywhere near it.
It parses by placing the '?' operator high in the order of operations; like I said. Do I really need to explain how order of operations works?
Why not indeed. I haven't seen any convincing use cases (and nor has the PEP, though I doubt Steve was looking for them), but they aren't inherently any more weird than "?." and "?[]".
It seems like a natural extension. It also seems like a lot to add for something as trivial as None handling.
While my immediate reaction is "yuk"
Is that more legit than my reaction to '?.' and '?[]'? At least in this case, the '?' comes at the end of a clause...
your use of "?" does not conflict with any use in the PEP, so this is a red herring.
I suppose it doesn't *technically* conflict, but it would lead to some beautiful code, like:
lambda data=a?.b?[0]?: data?.d