4 ms·
The examples in that PEP range from pointless (`if hi is None: hi = len(a)` => `hi ??= len(a)`) to cryptic (`libpaths = libpaths?.split(":") ?? []`). Remember
by pansa2 4y ago
The examples in that PEP range from pointless (`if hi is None: hi = len(a)` => `hi ??= len(a)`) to cryptic (`libpaths = libpaths?.split(":") ?? []`).
Remember the Zen of Python: “Readability counts”.
- phailhaus 4y agoThat latter "cryptic" example is exactly what Typescript looks like in some cases. But there, it works because the type system is guaranteeing you the correct return type, and can warn you when it's unnecessary. To add it to Python would be a huge mistake, because it would encourage throwing in ?'s everywhere "just in case", making it even harder to understand what's being passed around.
- pansa2 4y agoThe `?` operators also fit better within TypeScript's overall syntax, whereas Python traditionally prefers English words over punctuation characters. In a language which considers `and` and `or` more readable than `&&` and `||`, surely `is not None` is more readable than `??`.
- phailhaus 4y agoTrue, but it is tricky because `is not None` doesn't work here. For example, `my_var ?? 0` would become `my_var if not None 0` which doesn't really make sense and also collides with the pre-existing ternary syntax (`my_var if not None else 0`).