I've been fired a few times as a developer and I think your empathy approach is truly wonderful!

The first time I was fired it was entirely 100% my fault. I was a practicing alcoholic at the time(meaning I was still getting smashed by whisky every night) and it affected my performance, as well as my punctuality, energy levels, and concentration. I would show up late, fall asleep in meetings, and not really get much done. There was no surprise for me when I was let go and I had been given several warnings. My boss was my programming mentor all throughout college, and one of my best friends, so I can imagine it was really hard for him. Me and him are still friends and talk everyday though it took a month or so for me to mentally uncouple 'boss' him who fired me and friend him. Either way, he made sure some friends came over and hung out with me after and encouraged me and made sure I knew that if called for a reference that he would give me a good one. He also helped me brush up my resume and such which was a nice gesture. I was in a bad place at the time though and I still kept drinking so it took a long time to find a job, but that's not really here nor there. I would say depending on your level of knowledge of this employee, be sure to try and help him through maybe some external issues if you think he may have a drinking problem or medical issue, go through HR to do it most likely, but do try and give him the benefit of the doubt. I don't think most people enjoy being shitty employees, if they chose that career path there is most likely a reason, and being in the bottom percentile of professionals in their field is most likely not a life goal of theirs.

The second time I was fired was different. I wasn't a great culture fit, but mainly I was a victim of some politics from what I gathered after talking it out with my direct boss. There was a project which was the first I was made the lead of and the reqs kept changing until there were conflicting requirements and I told them as much and that the end product would be defective and could get into an invalid state, but then was ignored, and the project didn't work as they expected. It was a big release and so 'someone had to take responsibility' and it couldn't be my boss as he's the CTO and had all the passwords and more domain knowledge, so I was let go. At least that's what I gathered. Luckily, I had two months notice here and I was already swimming in recruiter offers at the time and had been looking anyways. MY boss told me privately that I was being let go and that the interviews we were doing were for my position and that I'm not supposed to know but he felt me being fired was dumb. When I was let go they told me that they had brought up some issues before in my performance reviews but they had not, but rather mentioned them offhand in company wide meetings that everyone in the company should keep in mind. Things like lunch is EXACTLY one hour and things, sometimes I would take like 1 hour 15 minute ones even though I would also skip lunch multiple times a week. Regardless, never brought up to me one on one. So be sure if you're going to mention improvement things, that you mention them EXPLICITLY to the employee, and also be willing to work with them if possible as they may even feel bad but not know how to bring it up. If they need an hour and fifteen for lunch everyday, and maybe have a good reason, perhaps just don't worry about it. Not saying that is the case, and my reasons weren't really anything besides apathy, but maybe they live a bit far out and have to go home for lunch to give their pet medication at lunch. The other thing that was nice here is they considered if I had family in the area who could help if I got into a pinch between jobs and also gave a small severance. Things like that can really help.

Lastly some other pieces of things are to do it privately, hopefully near some lesser used exit or another. They will be emotional I imagine, and the last thing they want is to describe why they are looking distraught while leaving the building. A walk of shame is just cruel. Offer to let them get their things after hours if they like. Also offer to let them use the computer again at that time and maybe bring an external cd burner and blank cd or supply a memory stick. We all 'know' not to use the work computer for personal things but many do, especially by accident or its the first job or whatever. They may have some documents they saved as pdf's like receipts or something they need off. Or an important account tied to their work email. I think my first job I was an idiot and tied my electric bill to my work email for instance. Allowing them that can be nice. Also perhaps allow them to write a letter or something to some employees that they were friends with that they may want to exchange contact info with to get lunch or something sometime.

As for morale on the team, I think keeping them around is most likely worse though. I mean if you've ever had a coworker who was just horrid and then things improved when they left for a different job, its like that if they are the kind of employee that needs to be fired but you keep them around.

To summarize though. Kindness is key. A person most likely isn't underperforming because they want to, rather some other issue may be at play, even if they can't fix it themselves after being warned. Be sure to give explicit warning, and also to give a good run-time to find a new job if possible. Many people don't have the reserves to be between jobs for long after all, especially people with other issues in their lives. Let them keep their dignity, and also to get their belongings/friends/relationships/digital info with dignity and respect.

If you have questions or something let me know and I'll try to answer them. Good luck and no matter what try not to feel bad if you've really tried to help them. In the end the only person you can truly force change on is yourself. It's not your fault. :)