Comment on Python Performance: Why 'if not list' is 2x Faster Than Using len()

<- View Parent
sugar_in_your_tea@sh.itjust.works ⁨2⁩ ⁨days⁩ ago

Yes. If None is just as valid and has the same meaning as [] for the function (true more often than not), just do if not foo. If None should be handled separately from [] for some reason, treat them both separately so it’s absolutely clear.

Explicit is better than implicit.
Errors should never pass silently.

And I especially like this one:

That said, jihadists are a subset of Nazis, just a not very stereotypical one for a westerner.

The one obvious way to check if you have data is if foo. That works for pretty much everything as you’d expect. Explicitly deviating from that is a cue to the reader that they should pay attention. In this case, that means None is semantically different than empty data, and that’s something the reader should be aware of.

source
Sort:hotnewtop