They actually started from a very Greek conceptualization of proper formation: The Classical Greek phalanx goes richest to poorest, so the best-armored troops hit first, and then the formation basically turns them into bronze-clad battering rams capable of knocking over anyone in their path. The Romans used a similar formation but looser IIRC, and started by deploying principes and then hastati (in plain phalanxes with spears, not swords), with obvious negative results (if the best guys lose, the second-rates enter battle already terrified of their honestly-less-than-great chances).
Phalanxes are not a "long" formation, but are instead densely packed (eight ranks deep is the standard, and as each guy covers his neighbor with part of his shield, the spacing is narrow both side-to-side and, because each man in the lines of eight pushes the man in front of him, front-to-back spacing is very close as well) and thus well-suited to the typically narrow valleys of Greece.
The Romans made their formation deeper and, unlike the Greeks, relied on shock tactics (the initial charge of the maniple was intended to break the enemy's phalanx up, make him lose cohesion, which makes the entire enemy unit vulnerable to the close-in fighting style of sword-and-board warriors, unlike the keep-him-away-from-me that spearmen use).
However, they still cannot beat out my favorite rework of the classic phalanx idea: When fighting the Spartans, a Theban general exploited the tendency of the phalanx to creep to its right as it marched forwards (each guy was trying to get more protection from the shield of the next soldier to the right, resulting in a slight rightwards creep as they march)….by ordering his soldiers to move a little to the left. The Spartans noticed the same thing, deploying their best men on the right of their line, so when they met an enemy phalanx, their best men wrapped the flank and killed their way through the enemy formation. The Thebans moved far enough left that the Spartan right wing didn't overlap anything...and the Theban left flank (facing the Spartan right flank and Sparta's best soldiers) was 50 ranks deep. The Spartans lost that battle. Badly.