Not all inventions can be effectively kept secret, and patents also have the benefit that what would otherwise remain secrets gets published.
I’m not in favor of the current patent landscape, but doing away completely with them would likely be throwing out the baby with the bathwater.