As others have mentioned, the Roman legions were designed for flexibility.
Originally, the legions were designed for warfare in Italy. Italy, in many cases, has very uneven terrain. On this terrain, the phalanx would not operate with any type of efficiency. On the other hand, Greece, and areas in Asia Minor had large open areas, which enabled large masses of infantry to operate effectively, especially using cavalry on the wings. Phalanxes were easier to command, since troops were tightly packed, and operated mostly straight ahead.
The early Roman republican legions operated in three basic lines -
- The Hastati were the lightest armed of the three lines. They carried a lightweight version of the pilum, and a short sword to engage in close fighting. They were lightly armored, if any, and were the youngest, least experienced.
- The Principes were the in the next order. They were the primary infantry. They carried two pila, wore armor, and carried the "Spanish" sword.
- The last were the Triarii. They were the most experienced and carried a heavier spear, designed for thrusting.
A latin phrase "ad triarios redisse" has survived. It translates as "To the third line", meaning a desperate situation.
The republican legions also had a number of Velites (very lightly armed), dispersed along the line at the area of most need.
The legions could operate on most any type of open ground. By design, the junior officers could operate with a bit of flexibility, giving them the ability to fill gaps, or take advantages of enemy weaknesses not seen from the legions' commanders.