Actually the colonisation of algiers ended the barbary corsairs pirate activity.
Ofcourse back then the normal population of algiers were not as well armed as the somalis are today. Nor are they doing anything so horrible that a colonisation is called for.