Mine is that the useState hook is an actual plague on the entire React ecosystem. Regardless of your opinions of React, if you wanna use something then use it right.

  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    3
    ·
    5 days ago

    Moreso correctness, not security. In the end, your user is shooting themselves in their foot, if they mutate a variable that they shouldn’t, and by making the variable private and only offering a getter, we document that.

    Having said that, there’s also big differences between languages and paradigms, though.
    In object-oriented / garbage-collected languages, you often pass around references to an object into so many places that you need to code defensively versus your own codebase. That’s why getters/setters were taught religiously during the height of OOP.

    In other paradigms, you often just have one place that uses an object and then you can …simply not shoot yourself in the foot there. When you control both the definition and the access, you don’t need to protect yourself from yourself. In particular, you would probably think twice before mutating an object anyways.

    • klankin@piefed.ca
      link
      fedilink
      English
      arrow-up
      0
      ·
      4 days ago

      Damn, I was gonna disagree but you bring up some good points.

      I really need to get into functional programming.

      • Ephera@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        4 days ago

        Functional programming is definitely worth a look in this regard as well, but what really drove this home for me is Rust.

        Its ownership+borrowing concept is exactly that, it enforces that you’ve got one place where an object is managed and in particular mutating can only be done in at most one place.
        Obviously, there’s also ways to get out of that, in case you do want some memory managed centrally, but it just isn’t the default.