r/badcode • u/Haaxor1689 • Mar 22 '23
js How to write code that does absolutely nothing in 30 lines, comment adds another layer to this insanity
418
Upvotes
r/badcode • u/Haaxor1689 • Mar 22 '23
155
u/Romejanic Mar 22 '23
Someone just learned about custom hooks for the first time huh
74
u/CountrysFucked Mar 23 '23
Gonna play devil's advocate here but is this just boilerplate setup ?
Also code reviewers. Nobody should be allowed to push code themselves. Not a senior, not a principal, nobody. 2 required or minimum one reviewer on all PRs to a shared codebase.
Unless this was reviewed. Then there's more than one person at fault.
10
u/PhatOofxD Mar 23 '23
This code doesn't just do nothing. It actively makes it worse / removes features. (No prev state in setter now)
48
u/sweetenthedeal Mar 23 '23
As someone who has applied to over 50 junior dev positions in the past month alone, the fact that someone who writes code like this has a job kinda annoys the hell out of me.
26
u/welshucalegon Mar 23 '23
async4
u/thekwoka Mar 23 '23
I really want to know why they thought the function should be async....
1
u/[deleted] Mar 23 '23
Now I’m angular dev, but what’s the point of the useCallback if all it does is mutate the state which is what the setCurrentFolderId hook (term?) would do anyway from the little react that I know.
3
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 23 '23 edited Mar 23 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
3
u/m2thek Mar 23 '23
I hate commented code. At best it adds unnecessary clutter, and at worst it creates a situation where you can't tell if someone fucked up something they were testing and you don't know which version is correct. (like, "startIndex = 4; // 5;")
If you comment out a block of code, pleeeeeeeease add a comment to explain why it's worth keeping. Otherwise, I'm getting rid of that shit the next time I'm in the area.
1
u/Haaxor1689 Mar 23 '23
I had a feeling this was going to be bad even before clicking on it. At least he was aware that the setter could be called with the previous state. Still, didn't quite get there. https://i.imgur.com/nIRSc4m.png
2
u/lifetimewinter Mar 23 '23
This code makes me very uncomfortable.
2
u/theOrdnas Mar 23 '23
that eslint-disable line is just the icing on the cake
1
u/[deleted] Mar 23 '23
At least he is using TypeScript. But that's about it.
1
u/greyspurv Mar 23 '23
As a coder through 6 years, I just wanna say, what even is that haha.
Yeah he prob. just discovered React Hooks.
3
u/[deleted] Mar 23 '23
[removed] — view removed comment