Imam ‘Abdallah ibn ‘Alawi al-Haddad-may Allah bless his soul-mentioned in his kitab, al-Fusul al-’Ilmiyya wa’l-Usul al-Hikamiyya (Knowledge and Wisdom):
The company one keeps has major effects. It may lead either to benefit and improvement or to harm and corruption, depending on whether the company is that of pure and eminent people or people who are depraved and evil. This effect does not appear suddenly, but is a gradual process that unfolds with time. The Messenger of God, may blessings and peace be upon him, said, “A man will be with his companions.” And, “A man’s religion is that of his intimates, so let each of you consider who he becomes intimate with.” He also said:
A virtuous companion is like the merchant of musk. Either he will offer you some, you will buy it from him, or you will find him pleasant to smell. But an evil companion is like the bellows-blower, either he will scorch your clothes or you will receive a rotten smell from him.
If you wish to know whether those you mix and sit with increase or diminish your faith, religion, and actions, compare your state with regard to good character, praiseworthy intentions, resolution in performing acts of obedience, and goodness before and after their companionship. If you find that these acts have become stronger and more firmly established and that you have become more desirous of and interested in them, then know that this particular company is of benefit to your religion and your heart, and that if you continue with it you will gain even greater benefits and acquire many more good things, God willing. If, on the other hand, you find that your religion has grown weaker and shakier, know that this company is harmful, that its harm to your religion and your heart is evident, and that if you continue with it it will lead to even greater harm and evil, may God protect us! You should also compare the bad points you had before and after keeping that company. This is the way to evaluate one’s position vis-a-vis those with whom one mixes and takes for one’s companions. The decisive factor here is whether good or evil is more powerful and predominant. When goodness in that company is more powerful and predominant, then a wicked man who mixes with them may become attracted to goodness and its people; whereas when wickedness prevails and dominates, then it is to be feared that the good people who keep such company may become attracted to wickedness and its people.
These are subtle concepts known to people possessed of discernment and who have experience in such matters. [The Prophet] said, may blessings and peace be upon him, ” A good companion is better that solitude, and solitude is better than a wicked companion.” [The Prophet], may blessings and peace be upon him, was given a comprehensiveness of expression that no other man, whether of ancient or of recent times, was ever given.