• calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      4 hours ago

      This is literally a getter function. How is a getter awful code? It’s the simplest function there is. The only function simpler than that is returning the input itself.

      • BrianTheeBiscuiteer@lemmy.world
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        7 hours ago

        How does “foo” mean “get”? Half the battle of writing correct code is writing code that’s easy to interpret. Do you always look at the guts of every function you’re about to use?

    • Ephera
      link
      fedilink
      arrow-up
      4
      ·
      1 day ago

      How would you make it non-awful, without specifying static types?

      I guess, a unit test would catch it, but needing 100% test coverage to catch typos isn’t exactly great…

      • BrianTheeBiscuiteer@lemmy.world
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        edit-2
        1 day ago

        What’s the purpose of foo? Why an ambiguous single character variable? What if the property was there but the value was null? Why not use (assuming JS) optional chaining?

        I’d approach it more like this:

        function getWhatevrProp(userData) (
          const default = { whatevr: "n/a" };
        
          return { ...default, ...userData }.whatevr;
        }
        

        Sorry, read too fast the first time. It’s more likely Python. I also don’t know Python well enough to give recommendations on that.

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          3
          ·
          1 day ago

          It’s an example to demonstrate that linters cannot reliably detect variable name typos - you need static types. None of the stuff you mentioned is relevant.

          The typo in your example is also undetectable by linters. I think you’re missing the point.