Most factory-built PTO shafts are telescopic (they slide in themselves) so that they can fit a number of applications and uses. If you are going to make up a dedicated shaft for a piece of equipment I suggest to following:
The goal is to keep the shaft and it's universal joints as straight as possible to limit vibration and eccentric motion. Most universal joints do not like to run at any angle more than 3 to 4 degrees from center. A PTO, since it spins only 540 rpm, is much more forgiving than a driveshaft on a car or truck. But the goal is to always keep it as straight as possible while in the use position. If a CV joint (constant velocity joint) is employed instead of a universal joint, then the angle is much more forgiving between the PTO and the driven implement. It can then become quite aggressive with a steep angle.
Another concern is the movement of the equipment and the tractor. The shaft needs enough length to slide in- and -out as the square tubes nests inside each other. Thus you must anticipate the actual amount of movement that may occur and then add about six more inches for enough depth to handle the torque load.
If the shaft is going to operate a stationary object such as an auger or irrigation pump, then three or so inches of freeplay (nesting) will suffice to make it easy to connect and disconnect.