• graycube@lemmy.world
    link
    fedilink
    arrow-up
    8
    ·
    19 days ago

    I would have liked some comments explaining the rules we are trying to enforce or a link to the product requirements for it. Changing the rules requirements is the most likely reason this code will ever be looked at again. The easier you can make it for someone to change them the better. Another reason to need to touch the code is if the user model changes. I suppose we might also want a different password hash or to store the password separately even a different outcome if the validation fails. Or maybe have different ruled for different user types. When building a function like this I think less about “ideals” and more about why someone might need to change what I just did and how can I make it easier for them.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      7
      ·
      18 days ago

      and how can I make it easier for them.

      I am wary of this. It is very hard to predict what someone else in the future might want to do. I would only go so far as to ensure nothing I am doing will unnecessarily block a refactor later on but I would avoid trying to add or abstract things in ways that make the current code harder to read because you think it might be easier for someone to add to in the future.

      I have needed, far too many times, to strip out some unused abstraction to do something that abstraction was never intended to allow because someone was trying to save me time and predict what might happen to the code in the future and got it completely wrong. It is far easier to add an abstraction to simple code later on when it actually helps then to try and figure out what the abstraction is and remove it when it is found to be wrong.

      • graycube@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        18 days ago

        Good point. I think knowing where to draw that line comes with experience (and having to fix lots of other people’s code).