• wizardbeard@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    11
    ·
    6 months ago

    Still hurts, but sometimes it’s the only option.

    If you’re trying to confirm things like account existence/deletion, there’s often no “account exists” function to return true or false. You just have to figure out the specific exception thrown and catch that specific one.

    The worst are libraries that don’t give specific exceptions, so you have to catch all exceptions then do extra work to tell what the specific situation is. Does the account not exist, or is the system unreachable?

    • prof@infosec.pub
      link
      fedilink
      arrow-up
      3
      ·
      6 months ago

      Yeah, I had a similar case with some authentication middleware I used that was part of a library.

      It would always throw an exception when a user wasn’t authenticated instead of just giving me some flag I could check.

      Wouldn’t have done it that way, but it was okay for an API controller.

    • Ethan@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      arrow-down
      1
      ·
      6 months ago

      so you have to catch all exceptions then do extra work to tell what the specific situation is

      That’s horrifying. That’s a solid reason to avoid Python like the plague.

      • Lightfire228@pawb.social
        link
        fedilink
        arrow-up
        4
        ·
        6 months ago

        While i also disagree with python’s tendency to use exceptions as control flow

        Python is a pretty stellar scripting language. I wouldn’t use it for app dev, but it’s quite handy for the odd automation or CLI task

        • Ethan@programming.dev
          link
          fedilink
          English
          arrow-up
          2
          ·
          6 months ago

          I’ve done a little bit of Python in the past, the biggest thing being an automation task that borderline became an app. I certainly can imagine using it for scripts, though I default to bash because that’s almost always available but TBH mostly because inertia. Beyond that my default is Go because inertia (and I love Go). I watched a video by the Primeagen (on YT) - in his view, Rust is better for text/data pipelines and CLI tools. Being very familiar with Go and not at all familiar with Rust, that’s an interesting take because honestly writing a CLI in Go is kind of meh.