T O P
Romejanic

Someone just learned about custom hooks for the first time huh


Haaxor1689

The guy that wrote this actually asked me "How do you code?". I was really baffled by that question at the time but now I understand what he meant. I can happily say he no longer works at our company.


Romejanic

Wow, glad you don’t need to deal with that anymore


Haaxor1689

Well, I need to clean up his mess of a project now. Everything is a state, there are like 5 different nested contexts in every part of the app, and effects bombarding our backend with fetches constantly.


Romejanic

Oh god. How did he even get hired


wubsytheman

This is what happens when managers and rando’s are convinced “anyone can code, they just watch Netflix and earn millions” lol


Mocker-Nicholas

Christ yeah. There are many, many, competent newbies struggling for a chance right now and this dude hits him with a "how do you code?" lol


lets_eat_bees

There's a strong opposition to live coding interviews. I can only imagine this is why.


Nacropolice

Not sure why. I think live is better than an isoteric leet code which has 0 bearing on what you will do


Romejanic

I find that really absurd, I had a live coding interview for my job and it was likely a really good way for my boss to see how good my practical coding skills were. Honestly it should just be a standard practice.


thekwoka

Yeah, I don't mind them. So far every one has been very easy, almost comically so. I have the issue of getting the interviews in the first place since my Professional experience is short. I can only do so much to leverage OSS contributions.


Romejanic

Yeah that was very frustrating, it takes a lot of tries to get a shot at a job. Even my bosses were saying they felt that they were taking a chance on hiring a graduate but they’re glad they did in hindsight. I think that fear would outright prevent some employers from hiring graduates. And yeah, mine wasn’t a particularly hard question. The only people who would have an issue with them are people who’s coding skills aren’t good enough to pass it, which is why they’re so resistant to them.


lets_eat_bees

It... is, right? It still is where I live. But a lot of people want it gone or deemphasized because it hurts people's chances. Yeah, it does - it really fucks up the chances of people who can't code!


True_Statistician645

I code better when someone is not looking over my shoulder. I can focus and its like my brain switches. If someone is watching over me I get extremely anxious, cant speak and just flop the whole thing. Its not because I cant code, its just how my brain works. Thats why I prefer an assessment rather than a live coding interview.


pwuk

Same, can't stand the false nature of the live coding interview, I don't know anyone who works that way. It feels like what I imagine stage fright to be.


Cerulean_IsFancyBlue

There are some arguments against it, but as an employer, I am definitely still using it. The high-level argument against it is that it can filter out qualified candidates, and you will miss out on potentially good employees. The high-level argument in favor of coding test is that it is very expensive for a company to hire a bad coder. Every good place I have ever worked, has made it more important to higher good people than to fill the available headcount quickly. Coding tests will possibly slow down your hiring rate, but they will help you avoid hiring duds. There’s a secondary argument, that, the way many people administer a coding test is not really good at filtering out the wheat from the chaff. The way you fix that is, teach your interviewers how to interview well. Coding tests that are too easy, that you took unmodified off of the Internet, that depend upon a single insight , and that have no ability to explore the problem area. Those are your problems.


ZedTT

> The guy that wrote this actually asked me "How do you code?". I need more info about this story. I need to know what he meant by this question


Haaxor1689

I think what he meant was, how do I come up with solutions to problems I need to solve? When he was given specific instructions on what to do, he just did that. But when he had to come up with his own solution, well, stuff this was born.


top_of_the_scrote

vim or intellij


FreshBootyInspector

Vim and pycharm baby let’s goooo


HeOfTheDadJokes

Same. Was it "how do you, specifically, code?" or was it "how does anyone code? tell me what I need to do."?


MenshMindset

That is such an insanely telling question lol


sweetenthedeal

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.


Cerulean_IsFancyBlue

Had.


CountrysFucked

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.


nan-000

Upvoted because I agree with the principles, but where is it implied this was not on a feature branch? heck might even be a local one, it's just a screenshot.


Haaxor1689

Nope, this is a production code that was running for 2 years now. It was a pretty small project that was done by a 2 man team, 1 FE and 1 BE engineer. They were just supposed to take an already existing project for another client that did basically the same and mirror it in this new one, that's why there was no one else to watch over them.


nan-000

Oh damn, if this was in production then the user I replied to is spot on, I don't think there's a valid reason to skip peer review but having a simple task is definitely not one of them. Either management and/or tech lead are also at fault here.


CountrysFucked

I've made an assumption as generally when people share these code snippets that are not their own it's because they found it in their shared repo and are frustrated as they will have to deal with it, which I believe from OPs responses is the case here but you could be right. Also I wouldn't judge people's feature branches. Should be a safe space to save your code as you develop. This person might have just started writing this hook and pushed half written progress or maybe they are just trying out something new with no intentions of merging.


welshucalegon

`async`


HeOfTheDadJokes

Just in case. You never know!


PhatOofxD

This code doesn't just do nothing. It actively makes it worse / removes features. (No prev state in setter now)


Haaxor1689

Yeah, even if this whole hook was replaced with a simple useState, it still would be completely redundant where it's used. There is a lot more from that project I could share, this was just a nice concise example.


thekwoka

I assume this hook is also only used in one place?


Haaxor1689

It's used 9 times so I guess he felt like a proper abstraction of `useState()` is needed at that point.


thekwoka

I guess, if they were legitimately concerned about the naming this isn't awful... Like it enforced the variable names in the destructuring...I guess? But the useCallback isn't doing anything... And this will likely cause issues where useEffects and stuff will want the setter in the dep array since they can't know what it really is...


thekwoka

Technically that would still work, but TS wouldn't like it.


PhatOofxD

Yeah haha


thekwoka

I really want to know why they thought the function should be async....


MurdoMaclachlan

*Image Transcription: Code* --- import { useCallback, useState } from 'react'; export const useCurrentFolderId = () => { const [currentFolderId, setCurrentFolderId] = useState( undefined ); const changeCurrentFolderId = useCallback(async (nextId?: string) => { setCurrentFolderId(nextId); }, []); return { currentFolderId, changeCurrentFolderId }; /* const currentFolderIdMemoized = useMemo(() => { return { currentFolderId, changeCurrentFolderId }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentFolderId]); return currentFolderIdMemoized; */ }; --- ^^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!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)


MeisterKarl

Minor mistake on row 5: `undefinedd`


alphabet_order_bot

Would you look at that, all of the words in your comment are in alphabetical order. I have checked 1,415,911,764 comments, and only 270,447 of them were in alphabetical order.


MurdoMaclachlan

Fixed, thanks for the heads up!


m2thek

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.


Special_Teaching_528

/* please don’t remove this, it generates my grandmas recipe for cookies */


lifetimewinter

This code makes me very uncomfortable.


theOrdnas

that eslint-disable line is just the icing on the cake


MrSlothy99

I honestly have no idea about react, could someone elaborate what the hell is going on here ?


Frown1044

It's a shitty abstraction for one line of code: `const [currentFolderId, setCurrentFolderId] = useState();` The rest of the code doesn't really do anything except make the code longer.


MrSlothy99

Oh alright ! Thanks !


Haaxor1689

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


Naraksama

At least he is using TypeScript. But that's about it.


Nacropolice

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.


Haaxor1689

The point of useCallback is supposed to be to memoize the function reference so it doesn't trigger unnecessary re-renders. Here it has no point since state setters from useState hook are memoized by default, it only wraps the already meoized function in anither function that is again memoized, bringing unnecessary overhead.


Nacropolice

Ah I see. Thank you. I guess my train of thought was tangentially related in the sense that I thought it was just adding unnecessary layers of abstraction


sefFano

Oh fuck for a second I thought this was my code, until I saw it's a hook xd


greyspurv

As a coder through 6 years, I just wanna say, what even is that haha. Yeah he prob. just discovered React Hooks.