On Mon, Jul 23, 2018 at 6:05 PM Giampaolo Rodola' <g.rod...@gmail.com> wrote:
> This: > > v = a?.b > > ...*implicitly* checks if value is not None [and continues execution]. > This: > > v = a > if a.b is not None: > v = a.b > > ...*explicitly* checks if value is not None and continues execution. > I think both of those are equally explicit. It's just that one notation is more concise than the other. Explicitness and conciseness are related but different things. When something is "explicit", as I understand it, that means it does what it says on the cover. There is no unstated behavior. The plain meaning of `v = a?.b` is that it expands to the longer form (`v = a; if a.b ...`), and it is just as explicit. This reminds me of something I read about once called Stroustrup's Rule <https://thefeedbackloop.xyz/stroustrups-rule-and-layering-over-time/> [1]: > For new features, people insist on LOUD explicit syntax. > For established features, people want terse notation. I think the "explicit vs. implicit" part of this discussion is probably better expressed as a discussion about "loud vs. terse" syntax. None of the operators in PEP 505 have implicit behavior, to the best of my understanding. It's just that the operators are new and have terse spellings. As a point of comparison, I think a good example of implicit behavior is type coercion. When you ask Python to add an int to a float a = 3 + 4.5 all that you've explicitly asked for is the addition. However, Python implicitly converts the 3 from an int to a float as part of the operation. The type conversion isn't anywhere "on the cover" of the + operator. It's implicit behavior. [1] Bjarne Stroustrup makes the observation in this talk <https://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Keynote> at 23:00.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/