system
Given the following post, respond as if you're commenting on Reddit:
human
Too deep of a function hierarchy makes debugging difficult?

I was talking with a more junior developer on my team last Friday, and we were having a discussion about some code that he had written (Javascript in React).  I was concerned that his function was a little too big and was trying to do too much, so I recommended moving functionality pieces into their own functions.

He pushed back some, basically saying that if the function hierarchy gets too deep, it's difficult to debug and understand, whereas if the logic is all in the same place, it's easier to debug and understand.

I had never heard anyone push back against breaking functionality out into separate functions, and off the top of my head, I didn't really have anything to come back with.  I've thought about it over the last few days, and I'm still not sure how I can impart what I'm trying to.

Is there a better way to explain the importance of what I'm trying to get across, or perhaps I'm not looking at this the right way?  I'd appreciate any input.  :)
gpt
I think the junior dev's view is simply due to inexperience.  The whole point of moving common pieces of code into a function is to *reduce* cognitive load by wrapping that chunk up into a single call the programmer no longer needs to think about.  The logic is still all there but now it's in a single (testable!) place and can be re-used anywhere.

Maybe come at this from a maintenance perspective.  Take some code you've recently worked on, manually inline as many function calls as you can, and ask the junior dev to debug it.  Then show him the original and ask which he prefers.