• Nerdulous@lemmy.zip
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 months ago

      I’d love to know why you say that. I’m learning the language and could use some insights

      • Starfighter@discuss.tchncs.de
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        3 months ago

        We are missing a lot of context but strong type systems give you the superpower to make unwanted state unrepresentable:

        Here we can see the class member invalid being used as a flag to express that this method didn’t work out as expected. It is very easy for someone else down the line to ignore/forget (/never even knew about it) to check that invalid flag and just use the result regardless, which will likely lead to more failures later on.

        Instead the author should directly return something that indicates invalidness. This could be as simple as returning a boolean or especially if this is a constructor it would be better to throw an error.

        That way the invalid class never even gets instantiated and is therefore impossible to misuse. All validated by the type system.

    • dev_null@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      If they choose to. I have the natural language suggestions enabled since it often helps me make my comments flow better. For this suggestion I’d add it to the ignore list, which you can always do.

      Of course you are not getting a post for the vast majority of actually useful suggestions it gives, like fixing accidental commas or typos (that result in a valid word, but one that doesn’t make grammatical sense where it is).