• Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    2 months ago

    Totally agree. The hardcoded isAdult: true repeated in all #2 examples seems like a bug waiting to happen; that should be a property dynamically computed from the age during access time, not a static thing.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      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
        2
        ·
        2 months ago

        Properties are great when you can cache the computation which may be updated a little slower than ever 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.

      • Eager Eagle@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        2 months ago

        Properties make semantic sense. Functions do something, while properties are something. IMO if you want to name something lazily evaluated using a noun, it should be a property.