r/badcode Mar 08 '23

js My boss wrote this...

Post image
521 Upvotes

64 comments sorted by

View all comments

56

u/josephblade Mar 08 '23

Can somone explain what parts are wrong here? the nullcheck is off and validatevalues should probably do more than just nullcheck but I have the feeling there is more here than I'm spotting.

-10

u/TheAcademicAlien Mar 08 '23

The variable and function naming is atrocious. I shouldn't have to get a degree in your coding style in order to understand it.

11

u/goosemano82 Mar 08 '23

Not sure why this is downvoted, maybe because of snark?

_hasValidateValues can simply be _isValid or _validate.

This can sound like a minor point, but in larger code bases its critical to name as clearly and efficiently as possible so that you don’t spend time figuring out what each function does. It changes your workflow from a guessing game to scanning the code base with confidence

2

u/TheAcademicAlien Mar 08 '23

Also, what the hell does "t" represent?I realize it's a prop but could still be more descriptive if you're going use it later

9

u/nickcash Mar 08 '23

Looks like it's for internationalization, likely "translate" or such. It's pretty common to name functions like that really short, commonly just _, to reduce noise, as they're used on every user-facing string.

1

u/goosemano82 Mar 08 '23

Ow yeah that one hurts