Ibn Jama’ah said:
“So, it is upon the student of knowledge to abandon socialization, as abandoning it is from the most important things that the student of knowledge must do – let alone with members of the opposite gender – especially with those who spend most of their time in play, and spend little of their time in thought, as the nature of individuals can rob you.
The harms of socialization include the passing of life without any benefit, as well as the decline of wealth and religious practice, if this socialization were to occur with the wrong people.
The student of knowledge should not mix except with either those who he can benefit, or can benefit from. And if he is offered the friendship of one who will waste his time with him, will not benefit him, will not benefit from him, and will not assist him in reaching his objective, he should politely end the relationship from the start before it progresses to something deeper, as when something becomes established, it becomes more difficult to change it. There is a phrase that is constantly on the tongues of the Fuqaha’: ‘Repelling something is easier than removing it.’
So, if he requires someone to befriend, let that person be righteous, religious, pious, wary, intelligent, full of benefit, having little evil, good at complying, rarely conflicting, reminding him if he forgets, cooperating with him when he is reminded, helpful if he is in need, and comforting if he is in distress.”
[‘Tadhkirat as-Sami’ wal-Mutakallim’; p. 83]