tongue (can mean language as well): a língua portuguesa, la lengua española.
language is different, Portuguese is feminine, and Spanish is masculine: a linguaguem de programação, el lenguaje de programación.
idiom is masculine in both: o idioma português, el idioma español.
While learning the language I've noted that in Portuguese words ending in ~gem are generally feminine regardless of their gender in French:
un garage -> uma garagem
un langage -> uma linguagem
un abordage -> uma abordagem
un bagage -> uma bagagem
And many, many others. My point is that I'm guessing that the diference in gender here is purely morphological and not tied to the meaning of the word and whether it's semantically tied to masculine or feminine traits (I'm sure you already knew all of that but I also know that English speakers often have misconceptions regarding how genders work in Romance languages, so I thought I'd clear it up).
When the transition from 3 gender to 2 happened, neuter words had to be "assigned" to one gender or another. Sometimes this was just arbitrary, other times conditioned by phonology or semantics.
The same phenomenon occurred when Sanskrit's 3 gender system gave way to the dual gender system of the new-Indo-Aryan languages like Hindi. In that case, most neuter words became masculine because they were often already phonologically similar to masculine words in the accusative case.
I have misconceptions about other Romance languages as well. I often confuse genders when trying to speak French, last week I learned moustache is feminine, while in Portuguese and Spanish it's masculine.