In the 18th century, a new pirate crew would come together to elect a captain and quartermaster, and agree on a shared code of conduct: what we today call the pirate code.

Black Bart – real name John Roberts, assumed name Bartholomew Roberts – was perhaps the most famous and successful pirate captain of the 18th century. A pirate named Howell Davis kidnapped him and convinced him to join the crew. Six weeks later, Davis was killed trying to kidnap the governor of Príncipe. The pirate crew came together to elect a new captain, and Roberts was their choice. Yes, this pirate ship (like many others) was a democracy.
Democracy saw some great leaps in the 18th century. Robert Walpole became the first prime minister of the Parliament of Great Britain around 1721; the American Revolution kicked off in 1776 and the French Revolution in 1789. But the pirate election that elevated John Roberts came before them all: he became captain in 1719.
This was one of the significant selling points of piracy. Traditional ships’ crews were under the thumb of the captain; if he was a cruel or incompetent man, the crew suffered. Pirates chose their captain; if he was cruel or incompetent they could just choose a new one. They also elected a quartermaster at the same time. That position was supposed to strongly represent the crew’s interest to the captain; the quartermaster shared executive decision-making with the captain.
So that’s the leadership sorted; what about the law? I was surprised to discover that the Pirate Code is not just a dramatic fiction. Many pirate ships, after electing a captain, signed up to “articles of agreement.” These set out how the crew would share out loot, how they would resolve disputes, and how they would punish deserters or cowards.
Roberts’ code shared the loot evenly, with extra portions for the captain and senior crew. Arguments between crew-members were resolved with duels (to first blood). Cowards and thieves were disfigured and marooned. You can read the full code in the second link below.
As for Roberts? The same day he was elected, he led the crew ashore to exact revenge on the killers of their former captain – and then captured two more ships and set sail for Brazil.