PEP 505 (None coalescing operators) thoughts

A further virtue of
self.vertices = vertices or []
and the like is that they coerce falsy parameters of the wrong type to the falsy object of the correct type. E.g. if vertices is '' or 0, self.vertices will be set to [], whereas the ternary expression only tests
for not-None so self.vertices will be set to a probably crazy value.
Doesn't seem like a virtue to me, seems like it's probably hiding a bug in the calling code, which may have other ramifications. Better to have the "crazy value" visible and fail faster, so you can go fix that bug.
Carl I have to agree. It isn't a "virtue", and it's best not to mask such mistakes. But it *is* a... property of the shorter construct that it's more forgiving, and doesn't have the same semantics. PS -- My first post, and I lost the "Re:" in the Subject, hence this orphan thread which I'm content to see go no further.
participants (1)
-
Brian O'Neill