Why did the romans seem to favor swords over spears when most of their fellow societies favored the reverse?

by dreamingofhope

Howdy everyone. I had two questions I wished to ask about tonight, so I made back to back posts, didn't see anything in the subreddit rules about that so I hope it is alright. Anyways onto my question.

To the best of my knowledge, spears and polearms were generally considered superior to swords in ancient warfare. Their greater reach granted an advantage by letting soldiers attack the enemy from further away, as well as allowing them to attack from the safety of defensive formations like a shield wall.

Yet from all that I have seen in historical texts and representations it seems that the Romans heavily favored the use of swords, at least in their infantry. Even in times when their neighbors seemed to be relying totally on spears. What was the reason for this? Did the Romans have some form of specialized tactic that made swords a better choice in their warfare? Was it a cultural tradition that they maintained despite the disadvantage? Were swords considered to be "higher class" that a spear?

Alongside this, to my understanding the Romans were a dominant military force at the height of their empire. If swords are less effective than spears it would be strange that they could achieve this? I know that Roman legions were considered to be exceptionally disciplined. Was this the reason they were so successful with swords? Or is it something else? Perhaps superior numbers or greater supply lines?

As a follow up question, if I may and if this is not beyond the scope of this subreddit, what is it with swords that made them so popular? As far as I'm aware of spears/polearms were far more effective and used in greater quantity in Antiquity and the high/late Medieval eras than swords ever were. Yet it seems any work set in the past or in a fantasy setting has swords as the predominant weapon (eg Arthurian Myth, Lord of the Rings, A Song of Ice and Fire). Is there a known reason why they seem to be over represented in western culture/media?

Ertata

u/wotan_weevil answered that quite comprehensively here just four days ago.

These two older answers by the same user have more outside links and references.

Also look here for an extended discussion by u/XenophonTheAthenian on pila-as-thrusting-spears specifically.