• 2 Posts
  • 5 Comments
Joined 2 years ago
cake
Cake day: June 11th, 2023

help-circle

  • One of the principles of the Pythonic style is: simple is better than complex.

    But is it when you consider ambiguity and expressiveness too?

    len(mylist) tells me it’s definitely a list and not null or whatever. It also tells me the intent of whoever writes the code was checking length.

    If it requires a long article to explain, I’d certainly be hesitant to use and prefer. The question is, is it surprising or intuitive that the truthy becomes a length check. What do you want to express with your code. And who will read it, and what expectations and requirements do you want to require of them.

    For sequence type objects, such as lists, their truth value is False if they are empty.