• WetBeardHairs@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    Neat. I don’t like that the implementations have to name the function by some cryptic identifier, though. Real words matter in source code.

    Who can tell me what this function is?

    def Z10096(Z10096K1):
        return Z10096K1 == Z10096K1[::-1]
    

    How about this?

    def isPalimdrone(myString):
        return myString == myString[::-1]
    
    • monotremata@kbin.social
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      It looks to me like they did it this way so that it could have natural-language names in many languages. So, the function Z10096 is called “is palindrome” in English, but if you’re coding in Japanese you can call it “回文の判定”. I don’t think the idea is for people to refer primarily to the alphanumeric soup version; I think that’s just the unique identifier for the database.

      It does look like it’s leading to some issues, though. E.g., someone added a test for the “is palindrome” function which uses a somewhat common example: “Straw? No, too stupid. I put soot on warts.” Now, a human would probably say that this is a palindrome, because it’s got the same letters forwards and backwards, but most of the implementations disagree, because they consider the spaces, capitalization, and punctuation to be part of the string; that is, they test whether the input string and its reverse are equal. So someone (possibly the same person) has added a second python implementation which ignores spaces, capitalization, and punctuation, and mentions that in its name on the page.

      Fundamentally this function is solving a different problem than the others (as demonstrated by the differing results on the relevant test), so should it get its own number and page? should there be a “palindrome disambiguation” page? This seems like something the site will have to figure out how to handle.