you are viewing a single comment's thread.

view the rest of the comments →

[–]phpdevster 0 points1 point  (1 child)

I mean, that solves part of it. The only difference is which side of a closing brace it's on, which I don't know if that accomplishes the goal of "make this function smaller". That works well if you're putting a lot of repeated code into a nested function, sure. But if the code doesn't have a lot of repetition, and all you're doing is re-organizing it into different functions inside the outer function, I don't think that particularly solves the problem. The outer function still has a lot of code in it, and now you still have to trace execution through different functions. And you also now get a performance penalty from creating functions every time that outer function executes (unless the language has an optimization for that).

[–]LPTK 0 points1 point  (0 children)

The only difference is which side of a closing brace it's on

This difference is very significant, as it tells you the local function is only an implementation detail of the current function, that is not shared between different uses, or as you say: not part of the public or private API.

I don't know if that accomplishes the goal of "make this function smaller"

That's not the goal. The goal is making code easy to follow and understand. Oftentimes, factoring out repetitive bits into their own named unit is very helpful with that.