At the beginning of Parshat Yitro, the Torah lists the names of Moshe’s sons. We are told that Moshe named his older son Gershom because he was a stranger in a foreign land (Midyan), and his younger son Eliezer because he was saved from the sword of Pharaoh. Commentators ask: Shouldn’t he have named his older son after the event that occurred first, as he was saved from Pharaoh before he went to Midyan?
Rav Moshe Feinstein explains that for Moshe, being a stranger in a foreign land was good. We know that he had amazing strengths and qualities and was probably offered a position of power, which he declined. Moshe knew that only if he remained a stranger in the land would he be able to keep himself from assimilating. To emphasize the importance of his being a stranger, Moshe named his first son Gershom. If Moshe had not remained a stranger in Midyan, he would have assimilated, and his escape from Pharaoh would have been pointless. Therefore, Moshe named his sons in the order that he needed to thank Hashem. First, he thanked Hashem for allowing him to avoid being influenced by the Midyanim, and only then could he thank Hashem for saving his life.