You believe that anyone can be trained to be an effective programmer. If that's true, then there's some truth to your argument: why not invest in education and training to meet the high demand for programmers?
But I disagree with that premise. I think "ability to be a great programmer" is generally something you're born with, or at least something that's been determined by the time you're ~18. Therefore it makes perfect sense to import programmers to meet the demand. The US population is just not big enough to meet the demand for programmers and it would be insane/damaging to the economy to refuse to employ non-Americans.
I think the reason for H1B workers is supply and demand. The demand for developers far, far exceeds the supply.