• Sem@lemmy.ml
    link
    fedilink
    English
    arrow-up
    7
    arrow-down
    1
    ·
    1 year ago

    To be honest, for me it looks as very strange pattern… If one wants to have static container with functions, there is Enums or classes.

    • Walnut356@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      It’s most useful when you’re using some data you already have as the dictionary key. A usecase i had for this was a binary file parser with 10 types of event markers. It was originally coded with if/elif, but performance was a pretty big consideration. Using the event markers as keys to a dictionary dispatch improved performance by about 15% and made the code significantly more readable.

    • Zeth0s@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      With classes you needs getattr in python to achieve the same. This is cleaner for simple mappings