• UndercoverUlrikHD@programming.dev
      link
      fedilink
      arrow-up
      10
      ·
      3 months ago

      I’d argue that if it’s strict explicitness you want, python is the wrong language. if not var is a standard pattern in python. You would be making your code slower for no good reason.

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        3
        ·
        3 months ago

        You always want explicitness when programming. Not everyone reading your code will be deep into Python and relying on falsiness makes it harder to understand.

    • ExtremeDullard@lemmy.sdf.org
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      3 months ago

      In complex cases where speed is less important than maintainability, I tend to agree.

      In this case, a simple comment would suffice. And in fact nothing at all would be okay for any half-competent Python cover, as testing if lists are empty with if not is super-standard.

    • sebsch@discuss.tchncs.de
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      I never understood that argument. If you can be sure the type is a collection (and this you always should) not list is so moch easier to read and understood than the length check.

      • Nalivai@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        3 months ago

        How many elements in that list? Ah, it’s not list. It’s list, of course, we checked. But it’s not.