Patents represent a deal: You publish specifications, and society will grant you exclusive use for X years. Thankfully, unlike their copyright cousins, patent laws have not seen an increase in X. This serves to prevent knowledge from being locked away as trade secrets.
Beneficial to society? Drug companies have patents, and patents expire. Upon expiration, generics become available because the synthesis of the drugs is public knowledge, which creates a competitive market and lowers the price.
Without patents, the drug companies could (modulo other regulations) keep synthesis of their chemicals a trade secret, which may not be replicable in a reasonable time-frame.