• Avicenna@lemmy.world
    link
    fedilink
    English
    arrow-up
    16
    arrow-down
    5
    ·
    edit-2
    1 year ago

    Yea and then you use “not” with a variable name that does not make it obvious that it is a list and another person who reads the code thinks it is a bool. Hell a couple of months later you yourself wont even understand that it is a list. Moreover “not” will not throw an error if you don’t use an sequence/collection there as you should but len will.

    You should not sacrifice code readability and safety for over optimization, this is phyton after all I don’t think list lengths will be your bottle neck.

      • taladar@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year ago

        It does if you are used to sane languages instead of the implicit conversion nonsense C and the “dynamic” languages are doing

      • Avicenna@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        arrow-down
        1
        ·
        1 year ago

        well it does not imply directly per se since you can “not” many things but I feel like my first assumption would be it is used in a bool context

        • thebestaquaman@lemmy.world
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 year ago

          I would say it depends heavily on the language. In Python, it’s very common that different objects have some kind of Boolean interpretation, so assuming that an object is a bool because it is used in a Boolean context is a bit silly.

          • Avicenna@lemmy.world
            link
            fedilink
            English
            arrow-up
            3
            ·
            edit-2
            1 year ago

            Well fair enough but I still like the fact that len makes the aim and the object more transparent on a quick look through the code which is what I am trying to get at. The supporting argument on bools wasn’t’t very to the point I agree.

            That being said is there an application of “not” on other classes which cannot be replaced by some other more transparent operator (I confess I only know the bool and length context)? I would rather have transparently named operators rather than having to remember what “not” does on ten different types. I like duck typing as much as the next person, but when it is so opaque (name-wise) as in the case of “not”, I prefer alternatives.

            For instance having open or read on different objects which does really read or open some data vs not some object god knows what it does I should memorise each case.

          • Glitchvid@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 year ago

            if not x thenend is very common in Lua for similar purposes, very rarely do you see hard nil comparisons or calls to typeof (last time I did was for a serializer).