On Sun, Sep 11, 2016 at 6:11 PM, Guido van Rossum <gu...@python.org> wrote:
> On Sun, Sep 11, 2016 at 6:00 PM, David Mertz <me...@gnosis.cx> wrote: > > None if a is None else a.foo > > This is the crux of the matter to me. It's just too verbose, and the > `if` and `else` keywords are lost in the noise of all the other words > on the line. Plus the big win when it applies) is that if `a` is in > fact something more complex, like `f(a)`, repeating it twice sounds > like a performance penalty, and that's where `f(a)?.foo` really > shines. > The non-repetition is certain a plus, I readily confess. It's not only performance even; `f()` might not be a pure function. Silly example: >>> def f(a): .... if random() < .01: .... return None .... class V: pass .... v = V() .... v.foo = random()*a .... return v -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/