Skip to content
DevMeme
2409 of 7590
Languages Post #2678 · source on Telegram

The Trailing Comma Hill

Description

A "Change My Mind" meme shows a man at an outdoor table with a code line overlaid at the top: "files = get_files(dir, pattern),". The sign on the table reads, "A comma at the end of a command should be an error, not create a tuple." The joke targets Python's syntactic rule where a trailing comma can turn an expression into a tuple, creating subtle type surprises instead of an obvious syntax failure.

Comments

14
Anonymous ★ Top Pick Python looked at a dangling comma and decided the parser was fine, but your type assumptions needed character development.
  1. Anonymous ★ Top Pick

    Python looked at a dangling comma and decided the parser was fine, but your type assumptions needed character development.

  2. @sylfn 5y

    a compilation error

    1. @mvolfik 5y

      More like complication error

    2. Deleted Account 5y

      Computation error 🌚

  3. @misesOnWheels 5y

    yes

  4. @GTRst 5y

    third-degeneration

  5. @sam0and 5y

    Python4?🤔

    1. @serghei_k 5y

      this

  6. @abel1502 5y

    At most a warning, but definitely not an error - it fits perfectly into the grammar model, and there aren't many reasons strong enough to force python to break its abstractions (which is its most wonderful aspect, in my opinion)

    1. Deleted Account 5y

      look at the walrus operator

      1. @abel1502 5y

        I've skimmed through pep572 (the one regarding exactly that), and while I wouldn't have considered this addition necessary on my own, it doesn't seem to break any pre-established abstractions, and the developers' rationale is compelling enough for me to accept it

        1. Deleted Account 5y

          well, you sould be fine then with comma too, bc both would require to just put parenthesis around those expressions

          1. @abel1502 5y

            That is quite reasonable, I agree. I guess the top-level tuple syntax is maybe allowed as one of the explicitly desired language features - tuple assignment (x, y = y, x), in particular. But you've got a good point nonetheless

            1. Deleted Account 5y

              oh crap, i thought that swap thing was magic, that's a good point too then

Use J and K for navigation