in reply to Can a large subroutine be split in two (e.g. parent and child relationship)?

Sure it can, if it has a single purpose you can put a name to.

To do that with ease, you can refine the big function bit by bit. Make sure that it doesn't assign to global variables, unless that's its sole purpose. Try to make the function return what it produces, getting all of its information from its arguments. That insulates the rest of the application from the functions' workings.

Now start cutting down big lists of initial my declarations, moving each lexical variable's declaration to where it is first assigned. Then move that assignment down to just before it is first used. Find where each variable is last used, and consider that spot for the end of a lexical block. The block which most closely corresponds to the new function you're thinking of will be the body of your new function. It will tell you which outer variables correspond to arguments of the new function, and which are internal to it.

This whole process is referred to as "refactoring", and it's worth the exercise to do it.

After Compline,
Zaxo

  • Comment on Re: Can a large subroutine be split in two (e.g. parent and child relationship)?