• rwhitisissle@lemmy.ml
    link
    fedilink
    arrow-up
    10
    ·
    2 months ago

    python guidelines

    Do you have a specific PEP you’re referencing or is this one of those “I assume this must be the case because of how common using try/except statements for flow control are” kind of things?

    • snekmuffin@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      4
      ·
      2 months ago

      Pretty sure its not a PEP, but the python glossary mentions it. Searching ‘python EAFP’ brings up a lot of discussion on the topic too, so if nothing else its definitely a widespread phenomenon

      • rwhitisissle@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        I think there’s a difference between “python guidelines encourage” something and “this is a common coding pattern.” Yes, you can use try/except for flow control, but there’s a lot of people, myself included, who try to use that style sparingly.

    • nxdefiant
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      Well, the phrase is older than dirt, but it was Grace Hopper that said it (in the context of computing), though, she was likely talking about a larger scope than flow control.

      Python is all about permissiveness, encouraging expressiveness. If the flow means checking->doing->handling is more expensive/less reliable/less maintainable than doing->handling, then you do->handle. Simple as.