How can people who jointly own a property prevent disputes over ownership or selling?

A declaration of trust setting out the shares and what happens if someone wants to sell, agreed at the outset, prevents most disagreements.