And be prepared for complete surprise. I've been involved in situations where one would have thought it was incredibly and abundantly clear to everyone involved that things were absolutely not working out. (Without going into a lot of details, heavy and extensive rework in multiple passes of projects they were working on over months.) Yet, getting fired was apparently a complete bolt out of the blue.
If it's in any way a surprise than it's 100% your fault as a manager. Having to 're work code' is so common in software it's basically normative. I've never written code that was not re-worked. So that, in and of itself might not be enough information. I understand it can be very difficult with someone who just isn't up to snuff, because it's like telling a mediocre athlete to 'be spectacular' - often it just can't work out. But it still shouldn't be a surprise. Moreover, if they're otherwise decent you could try to find something else for them to do.
Some people write terrible code but they are wicked problems solvers, I've seen them work out on integration teams that need people 'on the ball' hunting down problems.
In one case in particular, I wasn't the manager and it wasn't software but it was something similar (research/writing) where iteration is to be expected. However, this was a case where the person had to be held by the hand through rewrite after rewrite with others ultimately doing most of the work.
Should the employee have been given a clear "improve or you're gone" early on? In retrospect, yes. On the other hand, workplaces that have a low patience for people who don't quickly get to full running speed aren't necessarily the best places to work. And, to use your analogy, if you're dropping a lot of balls as a receiver, the coach shouldn't need to tell you that your job is at risk.
This was also a very small company so there really weren't other types of positions. It also meant there weren't a lot of formal processes. On the other hand, the connection between work and results was pretty clear.
I agree with your points as a general principle. On the other hand, it's reasonable to expect some degree of self-awareness which can be lacking to a surprising degree.
No surprise. If somebody is surprised when you fire them, you failed. You should have brought the issues up and explain what the paths to fix the are, the timeline, and consequences.
I don't think it's so much Dunning-Kruger as just being being almost willfully oblivious to signals that are trying to tell you things that you really don't want to realize. (As opposed to simply choosing to ignore what you know in your heart is really going on.)
That's really self-serving bias at work. It's also why the part about leaving zero ambiguity is so important. It's exactly the kind of people who didn't see it coming (while you thought you transparently had them on their very last shot) who try to bargain or give you that very, very, very last chance.
Surprises like this are rather rare, but emotionally straining for both sides: The surprised ones also are the ones with zero contingency planning or backup plan, but at some point it's really not your fault anymore if you communicated openly all along.
It's a life changing experience having someone break down in front of you, but in the end, it's a neccessary experience for both sides and a learning chance too. Your job as a leader is continuously balancing the needs of the individual with the needs of the team. And at the point you finally decided, your team already knew it wouldn't work out for a much longer time than you (if you hired right). It's your job to pull it through and not let the team get dragged down any longer.