this post was submitted on 25 Sep 2024
886 points (97.4% liked)

Programming

17080 readers
273 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] BrianTheeBiscuiteer@lemmy.world 1 points 3 days ago* (last edited 3 days ago) (2 children)

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.

[–] calcopiritus@lemmy.world 4 points 2 days ago

Lmao, and they say dynamic typing is supposed to speed up the developer.

[–] FizzyOrange@programming.dev 3 points 3 days 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.