• nous@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 months ago

    Or just a function. IMO computer properties are an anti pattern. Just adds complexity and confusion around what is going on - all to what? Save on a () when you access the value?

    • astrsk@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      Properties are great when you can cache the computation which may be updated a little slower than every time it’s accessed. Getter that checks if an update is needed and maybe even updates the cached value then returns it. Very handy for lazy loading.

      • nous@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        arrow-down
        1
        ·
        2 months ago

        Functions can do all this. Computed properties are just syntactic sugar for methods. That is it. IMO it makes it more confusing for the caller. Accessing a property should be cheap - but with computed properties you don’t know it will be. Especially with caching as your example. The first access can be surprisingly slow with the next being much faster. I prefer things to not do surprising things when using them.

        • astrsk@fedia.io
          link
          fedilink
          arrow-up
          1
          ·
          2 months ago

          I get that, it’s a valid point. But in OOP, objects can be things and do things. That’s kinda the whole point. We’re approaching detailed criticism of contextless development concepts though so it kinda doesn’t matter.