The standard NXT-G programming system for the NXT includes a feature called "My Blocks" that lets you create your own custom programming blocks. This is especially useful when developing complex programs, so that you can build up more complex actions from simpler actions that you can re-use. Although creating a simple My Block is not hard, it gets trickier to make more complex and more useful ones, and there are a number of practical concerns.
For anyone wanting to learn more about My Blocks, I have posted this web tutorial, which starts at the basics and works up to more complex uses, including input and output parameters, simulating local variables, and various practical concerns such as testing and maintenance.