3 ms·
I'd argue the first one is not a smaller WTF than the latter. It's a silent failure that also mutates state, arguably worse than getting a crash. With that sai
by dchftcs 1y ago
I'd argue the first one is not a smaller WTF than the latter. It's a silent failure that also mutates state, arguably worse than getting a crash.
With that said, a = b = [1,2] itself is a bit of a code smell, but I don't take issue with it here because it can arise in more subtle ways sometimes.
- pansa2 1y ago> I'd argue the first one is not a smaller WTF than the latter. I think the first one probably arises more frequently, but at least there's a fairly straightforward explanation: "`x += y` acts in-place if-and-only-if `x` is mutable". The second example is more niche but it's much harder to explain what's going on - it can only be understood by first understanding the first example, and what it implies about the implementation of `+=`.
- zahlman 1y ago> but at least there's a fairly straightforward explanation: "`x += y` acts in-place if-and-only-if `x` is mutable". This is the explanation. By definition it is only possible when the left-hand side is mutable; and in these cases, it's also typically convenient. This was apparently seen as "although practicality beats purity" rather than "special cases aren't special enough to break the rules".