
On Thu, Jul 19, 2018 at 5:29 PM Steve Dower <steve.dower@python.org> wrote:
* "It makes it more complex" * "It's harder to follow the flow"
Depends on your measure of complexity. For me, I prioritise "area under the indentation" as my preferred complexity metric (more lines*indents == more complex), as well as left-to-right reading of each line (more random access == more complex). By these measures, ?. significantly reduces the complexity over any of the current or future alternatives::
def f(a=None): name = 'default' if a is not None: user = a.get_user() if user is not None: name = user.name print(name)
You left one out, I think, that looks decent. I converted the print to a return, because I think it's more common to return than print. def f(a=None): try: return a.get_user().name except AttributeError: return 'default' def f(a=None):
print(a?.get_user()?.name ?? 'none')