• Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      3
      ·
      2 hours 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
        ·
        edit-2
        2 hours 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.