gyanendraknojiya@programming.dev to Programming@programming.devEnglish · 6 hours agoProgramming in simple 4 stepsprogramming.devimagemessage-square29fedilinkarrow-up1434arrow-down113
arrow-up1421arrow-down1imageProgramming in simple 4 stepsprogramming.devgyanendraknojiya@programming.dev to Programming@programming.devEnglish · 6 hours agomessage-square29fedilink
minus-squareBrianTheeBiscuiteer@lemmy.worldlinkfedilinkarrow-up4arrow-down6·3 hours agoAlways love seeing the trope: *writes awful code* See! This is why this language sucks!
minus-squareEphera@lemmy.mllinkfedilinkarrow-up3·2 hours agoHow 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…
minus-squareel_abuelo@programming.devlinkfedilinkarrow-up1·18 minutes agoI use a spell checker in my IDE. It would catch this.
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up1·2 hours agoWhat’s awful about this example? The only thing I do is access an object member. Does your code not do that??
minus-squareBrianTheeBiscuiteer@lemmy.worldlinkfedilinkarrow-up1·edit-22 hours agoWhat’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.
Always love seeing the trope:
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…
I use a spell checker in my IDE. It would catch this.
What’s awful about this example? The only thing I do is access an object member. Does your code not do that??
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.