• mint_tamas@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 days ago

    I think pythonic is more important than performance and I would still choose that version over a try-catch block, were it slower. Being pythonic means it represents a commonly understood pattern in Python code, therefore it is more efficient in communicating intent.

    • sugar_in_your_tea@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 days ago

      Exactly. The point of following a code style is to make obvious patterns easy to spot and deviations stand out. That’s why code style guidelines say your priorities should be:

      1. follow whatever style the code around it uses
      2. follow project style guidelines
      3. do the technically optimal option

      3 should only be prioritized if the win is big enough, and there should probably be a comment right there explaining why the deviation was made.