• idunnololz
    link
    fedilink
    861 year ago

    Just create a global object and stuff your variable in there. Now you have a global singleton and that’s not a purely bad practice :D

    • magic_lobster_party
      link
      fedilink
      411 year ago

      Not necessarily a bad practice if the singleton is immutable, and it’s provided via dependency injection for example.

      • Midnight Wolf
        link
        fedilink
        English
        381 year ago

        As a hobby coder: “mmmhm, mmmm, mmhm… I know some of these words!”

        • @SkyNTP@lemmy.ml
          link
          fedilink
          37
          edit-2
          1 year ago

          Software dev is full of obscure keywords that describe otherwise pretty simple or basic concepts you stumble upon in practice naturally and that you probably already understand.

          • singleton: a class/object that is designed to be single use, i.e. only ever instantiated with a single instance. Typically used when you use class/objects more for flow control or to represent the state of the program itself, rather than using it to represent data
          • immutable: read-only, i.e. unchangeable
          • dependency injection: basically when you pass a function or object into another function object, thereby extending their effective functionality, typically for modular code and to separate concerns.

          Here’s one more of my favourite examples of such a keyword: memoization

    • @xmunk@sh.itjust.works
      link
      fedilink
      9
      edit-2
      1 year ago

      Real enterprise programmers know that everything should be on the stack… so they declare a List《void*》 in main.

      • idunnololz
        link
        fedilink
        81 year ago

        But we might need to add more features in the future so it might not just be a list in a few years. Better encapsulate it in a few layers of abstractions just to be safe.

    • z3rOR0ne
      link
      fedilink
      31 year ago

      Ah yes. Global Objects, AKA the thinnest of condoms, lol.

    • Hurglet
      link
      fedilink
      11 year ago

      I do this all the time in Python by creating a class like

      class Core:
          foo = "bar"