Yeah, but some things cost a lot of money to develop. The higher the cost of the R&D, the less likely it is to occur without some patent system. Although I agree that in programming specifically the Open Source model seems to work quite well - look at the Apache Foundation.
You could have a model where all research was done by a public body or something like the Apache Foundation, but this reduces innovation as it means there is less opportunity for some people to try something that may not be considered likely to be successful, as publicly funded research tends to focus on the safest path. For an example, look at how public nuclear fusion research is continuing on the traditional toroidal tokamak model with ITER compared with the more experimental designs being tested by private companies such as Helion, Focus Fusion, Tokamak Energy (they are using a high aspect-ratio 'spherical tokamak).
Fundamental science is mostly publicly funded though and has little immediate practical application. The lack of funding in much of science also shows the problems this approach has.