Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
As you can see, creating subroutines is the smart way to go, but it does you no good to have multiple copies of subroutines scattered throughout all your scripts. If you needed to update a certain subroutine, you'd have to search for half a dozen (or more) copies of the same subroutine.
The smartest thing to do is to create libraries of subroutines and then load those libraries when you need them. For example, you could create a math library that contains your factorial() subroutine, save it as a compiled script, and then use the load script command to make whatever subroutines are in that library available to other scripts.