For drugs, patents:
1. Successfully provide a profit
2. Are necessary to provide said profit
3. Are long enough to provide enough profit to pay back the investment
But it's not clear that they're short enough to encourage further rapid improvements. Like, suppose a patent lasts 20 years but would still be worth pursuing even if it lasted only 5 years; that's 15 years of public development opportunity lost, for each patent.
Currently, the system is that the government declares "X years" by fiat. If it's too short, then corporations can lobby for longer patent durations. If it's not too short, then corporations can lobby anyway. This is a functional but mediocre system, and there's clearly room for improvement.