

But I’d push back on the idea of “The same code you made” being special. Code is just language and math put together. Take a sentence. “Hi, how are you?” under patent rules once someone patents that specific way to say this nobody else can do it. You can do the same function but have to phrase it differently. Like “Hello, are you well?” and eventually this just gets silly. Being the first to do something the most obvious way to do it shouldn’t give you a right to not let anyone else do it that way.
Why not ? In the end I used my money to come up with a way to do things, I would argue that I am entitled to stop someone else to simply stole it and I can always license you my work so we both can make some money, you selling something without the need to reinvent it, I selling you something so I can recover my initial expense. (which is the idea behind patents in the first place)
The point would be to not have silly patents in the first place.

So you basically say that patents are wrong just because we have silly patents (and even sillier laws basically).
I don’t think that “my money/time” means “something unique” but I think that if I built something new spending my money and my time then I can ask to have it protected for some years in order to be able to make some money to recover the amount I have invested to build it.
The problem is that we should have a trade-off with patents: we need to somewhat protect who invest his money to develop thing from who just copy it and undercut him and be sure that the patents do not stop innovations.
Like your surgeon example, I think that there can be right way to have patents, a good way and bad way. Now we have patents in the worst possible way. A better way would be to allow to register a patent only if you sell a product that use it and only valid for a limited time, for example.
After all, why should someone invest, say, a couple of million $ to develop something and trying to sell it at, say, 100 $ to break-even in 5 years knowing that the moment he sell someone can copy it and sell it for 20 the very next day ?
This is an interesting point and I agree that there is no solution with patents, the first to arrive is the winner. We maybe can have something like a grace period (if you fill a similar or equal patent in the next 2 months than both are valid) but in the end it is a race and the winner take all.