Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
PEP 0505 – None coalescing operators (python.org)
2 points by hk__2 on Sept 19, 2015 | hide | past | favorite | 1 comment


I can kinda see the need for "x ?? default", but the "Null-Aware Member Access Operator" and "Null-Aware Index Access Operator" should have examples of how it would improve code.

The text gives an example of current code:

  data = [] if data is None else data
then argues:

> This particular formulation has the undesirable effect of putting the operands in an unintuitive order: the brain thinks, "use data if possible and use [] as a fallback," but the code puts the fallback _before_ the preferred value.

I tried, but I don't see this as unintuitive. I would like more than the proposer's intuition as justification. Eg, is there any evidence that developers or reviewers have a tendency to confuse these by accident?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: