13

I am putting this question to C++ programmers because: a) Only a C++ programmer can judge the technical merits of the examples; b) Only a programmer will have a feel for the temperament of another programmer who writes code like this.

HR and the directors are aware there is a problem simply because they see evidence in the field. It's my call whether we give the programmer in question more time. Many of the errors are at a very basic level - my question (to programmers) is whether someone who professes to be a senior C++ developer should be given a benefit of a doubt based on samples of their current code. Non-programmers - even people outside C++ programming - can't make any judgement on this.

For background, I've been assigned the task of managing developers for a well-established company. They have a single developer who specialises in all their C++ coding (since forever), but the quality of the work is abysmal. Code reviews and testing have revealed many problems, one of the worst being memory leaks. The developer has never tested his code for leaks, and I discovered that the applications could leak many MBs with only a minute of use. User's were reporting huge slowdowns, and his take was, "it's nothing to do with me - if they quit and restart, it's all good again."

I've given him tools to detect and trace the leaks, and sat down with him for many hours to demonstrate how the tools are used, where the problems occur, and what to do to fix them. We're 6 months down the track, and I assigned him to write a new module. I reviewed it before it was integrated into our larger code base, and was dismayed to discover the same bad coding as before. The part that I find incomprehensible is that some of the coding is worse than amateurish. For example, he wanted a class (Foo) that could populate an object of another class (Bar). He decided that Foo would hold a reference to Bar, e.g.:

class Foo {
public:
    Foo(Bar& bar) : m_bar(bar) {}
private:
    Bar& m_bar;
};

But (for other reasons) he also needed a default constructor for Foo and, rather than question his initial design, he wrote this gem:

Foo::Foo() : m_bar(*(new Bar)) {}

So every time the default constructor is called, a Bar is leaked. To make matters worse, Foo allocates memory from the heap for 2 other objects, but he didn't write a destructor or copy constructor. So every allocation of Foo actually leaks 3 different objects, and you can imagine what happened when a Foo was copied. And - it only gets better - he repeated the same pattern on three other classes, so it isn't a one-off slip. The whole concept is wrong on so many levels.

I would feel more understanding if this came from a total novice. But this guy has been doing this for many years and has had very focussed training and advice over the past few months. I realise he has been working without mentoring or peer reviews most of that time, but I'm beginning to feel he can't change. So my question is, would you persist with someone who is writing such obviously bad code?

user94986
  • 179
  • 1
  • 4
  • 15
    If you already saw that he was writing bad code, why have you let him write his shit during 6 months without supervising him ? – BMN Jun 26 '13 at 14:18
  • @Yellow Bird: "If you already saw that he was writing bad code, why have you let him write his shit during 6 months without supervising him" He hasn't worked on anything new during that time. Mostly bug fixing and repairing old code. My hope was that it would translate into better new code when he next had the chance. – user94986 Jun 26 '13 at 14:33
  • 4
    IMO, when you see someone doing bad job for a while, you CAN'T let him work alone even if it's only debugging / repairing. If it is your will to keep him into your company, you HAVE TO supervise him and AFTER see if you still get bad results from him. Letting him work alone during 6 months without looking at him is IMO a bad management. – BMN Jun 26 '13 at 14:37
  • Have you already told him how bad his code is? Maybe he just does not realize, and no-one told the obvious? – Marcel Jun 26 '13 at 14:39
  • possible duplicate of [How do you disarm a cowboy coder?](http://programmers.stackexchange.com/questions/157251/how-do-you-disarm-a-cowboy-coder) and of [How to “neutralize” those who write bad code on the team?](http://programmers.stackexchange.com/questions/89883/how-to-neutralize-those-who-write-bad-code-on-the-team) – gnat Jun 26 '13 at 14:44
  • @Yellow Bird: "Letting him work alone during 6 months without looking at him is IMO a bad management." As I noted my message, I've spent a lot of time with him to explain the problems and demonstrate the solutions. Much of the work he has done on the old is implementing these changes. But the perplexing thing is that he's returned to writing new code with the same old problems - I'm beginning to wonder if there's any hope for him. – user94986 Jun 26 '13 at 14:45
  • 1
    Sometimes bad habits last long when they're not torn out of the developer when he's junior. – Andrzej Bobak Jun 26 '13 at 14:46
  • @gnat: "possible duplicate". Not really - I'm in a position to simply fire him and he knows it. I'm wondering (as Andrzej Bobak suggested) whether this id old habits dying hard, or if he simply isn't cut out for the job. Some of the code is so bad, I can't help wondering if I'm wasting my time. – user94986 Jun 26 '13 at 14:48
  • 3
    @user94986 Then if you spend time with him, explaining him that his habbits are bad, you should keep an eye on him, and if nothing changes, don't wait 6 months to speak to him. – BMN Jun 26 '13 at 14:51
  • 4
    If he doesn't think that memory leaks are a problem, there is no sense to teach him how to avoid them and give tools assisting with this. The main problem may be that he incorrectly understands goals and requirements for the product. – maxim1000 Jun 26 '13 at 15:41
  • Don't do your job well after it has been pointed out and specific intructions were given to make corrections and you still don't do your job, you have to go. For whatever reason, this person is not going to be able to grasp new concepts. – JeffO Jun 26 '13 at 16:13
  • Could someone explain why `Foo::Foo() : m_bar(*(new Bar)) {}` is a leak? I'm not a C++ programmer. I understand why "Foo allocates memory from the heap for 2 other objects, but he didn't write a destructor or copy constructor" is bad but not the first bit. – Peanut Jun 26 '13 at 16:33
  • @Peanut: A `new` without a corresponding `delete` results in a memory leak. Given that there is also another constructor that takes a `Bar` reference from outside, you can't know if `m_bar` refers to a `Bar` that you allocated and therefore, you can never safely deallocate it. – Bart van Ingen Schenau Jun 26 '13 at 17:27
  • 2
    This question appears to be off-topic because it is about what is effectively HR legal advice which is problematic for us to provide at best. –  Jun 26 '13 at 20:44
  • 2
    @WorldEngineer: disagree. Don't see a legal question in here at all. It's about merit and whether it is worth putting more effort into the person. – Marjan Venema Jun 26 '13 at 20:49
  • Funny how even when community overrules moderator decision and reopens the question, that question gets closed anyway. http://www.codinghorror.com/blog/2005/11/software-apprenticeship.html - consider that software development is just about the only engineering profession that doesn't follow apprentice/journeyman/master model. Did this guy ever have a mentor? College is terrible at teaching people how to code. Are you willing to mentor him now? Is he willing to be mentored? Even ability to learn on his own would improve if he started off right, which clearly up until now he hasn't – DXM Jun 26 '13 at 20:51
  • @DXM - Please feel free to open a question on [meta] about this. –  Jun 26 '13 at 20:55
  • @GlenH7 - that wasn't so much of a question as an observation – DXM Jun 26 '13 at 20:57
  • @World Engineer: I'm not an HR person and I'm not looking for legal advice. I'm a developer who is increasingly managing other developers. Perhaps I've been lucky, but all the developers I've worked with in the past were very professional and cared deeply about problems in their code. A developer who has worked in the field for so long and yet makes very basic mistakes and doesn't seem that bothered is a new experience. It seems symptomatic of a deep-seated problem, in which case he might be a waste of time. But maybe other developers have seen better outcomes. Comments are all helpful – user94986 Jun 27 '13 at 10:19
  • This question was closed by the community, then reopened via a bug in the reopen queue. I closed it for as best a reason as I could figure out given the community's original close reason which was "off-topic". –  Jun 27 '13 at 11:17
  • Maybe this question fits better in the workplace@stackexchange? – Andrzej Bobak Jun 27 '13 at 11:28
  • @Andrzej Bobak: I was looking for opinions from colleagues with experience of C++. I didn't want legal/HR responses or management advice. My view was that someone genuinely experienced in C++ would never write code like the example provided, which suggests the author either doesn't have an aptitude for programming or is lazy. If so, all the techniques in the world aren't going to help. But perhaps other C++ programmers might have a different view - I'm disappointed we aren't allowed to ask questions of a technical nature here just because it contributes to a management decision. – user94986 Jul 05 '13 at 10:44
  • @World Engineer: Is there another forum that experienced C++ programmers will read where I can post this? – user94986 Jul 05 '13 at 10:46

8 Answers8

22

My advice would be to confront him about this particular example and see what he says. If he denies there being anything bad with the code, then I'm afraid there is little you can do. If he accepts that he made a mistake (even if he's defensive about it), then at least there is room for improvement. If you accept the time and effort on improving him, then you or a senior programmer will need to sit him down and code together until all these tendencies are flattened out (be prepared to dedicate this person for at least 1 months time).

A bad programmer, I can usually work with, but a programmer who can't improve, I cannot.

Neil
  • 22,670
  • 45
  • 76
  • 12
    +1 for *"A bad programmer, I can usually work with, but a programmer who can't improve, I cannot."* –  Jun 26 '13 at 16:08
  • Yeah, also, I would let the guy know it's pretty serious. It sounds like he hasn't been told or hasn't acknowledged that there's a problem for years. Come to the conversation ready to point out examples of stuff he shouldn't have done and how it impacted the quality of the app. If he's still not willing to fess up to a problem with his code, I'd probably let him go. And I probably wouldn't give him a lot of time to get his act together if he did. You definitely need to underscore that his future at the company is at stake and that he's lacking in a pretty critical skill for a C++ dev. – Erik Reppen Jun 26 '13 at 16:11
  • @ErikReppen I agree, but I also think programmers can be the most stubborn types of people on earth. If you push too hard, he may deny any problems with his code simply due to being defensive. I think it's important to emphasize the gravity of the situation, but I would still try to sympathize with him *"I happened to notice this little mistake. Did you happen to catch it too? Do you suppose you made this same mistake in other areas of your program?"* – Neil Jun 26 '13 at 16:20
  • @Neil The only way through a wall of stubborn is a kick in the ass. And I speak from experience as the stubborn ass side of that equation. That said, if it's the first he's heard of there being an issue with his code, yes, I'd go a little softer but it sounds like they've tried to communicate an issue at least once before – Erik Reppen Jun 26 '13 at 16:24
  • @ErikReppen Maybe, but you risk that he shapes up just to get you off his tail. At that rate, you might as well say "Shape up, or you're fired." At least this approach finds out if he's conscience of his errors. – Neil Jun 26 '13 at 16:43
  • @Neil This is a good point. I definitely wouldn't start with the threat aspect but he does, IMO, need to understand that it's a serious problem and that no, they're not just being fussy. – Erik Reppen Jun 26 '13 at 16:47
18

So my question is, would you persist with someone who is writing such obviously bad code?

No. I would fire any professional C++ developer that lacked the basic understanding of memory management.

If it's someone coming from Java or C# or something I'd give them some lattitude, but this is pure incompetence.

Telastyn
  • 108,850
  • 29
  • 239
  • 365
  • 9
    I can't understand how this answer can be upvoted. Firing someone is not a matter that should be taken lightly. – Florian Margaine Jun 26 '13 at 18:39
  • 3
    @FlorianMargaine - Sure, but this seems like a clear cut case. How much is this employee costing the company in lost sales due to memory leaks or security vulnerabilities? How much in lost time to testing/fixing this crap? How much in having the OP babysit them? How much in having other programmers' suffer from his [mere presence](http://online.wsj.com/article/SB10001424052970203499704576622550325233260.html)? Unless the employee has an absurd amount of domain knowledge (or blackmail), there is no way that replacing them is more costly. – Telastyn Jun 26 '13 at 20:43
  • 1
    @FlorianMargaine, This type of employee is who doesn't get fired enough, it cripples the company in difficult to fix technical debt. It says in big red lights, "They don't care, so why should we?". Know what the employee you really want would say? "... but i do care, so I need to go to a place that does". The bad ones already didn't care, so they remain at your office. You MUST remove people who hurt productivity, more than they contribute. This isn't a choice taken lightly, however it really is a clear line, failure to act is a clear action. – J. M. Becker Jan 13 '18 at 17:38
13

We can't answer the broader part of your question. Namely, should you retain or fire that employee. Firing an employee is difficult, but that's a decision outside the purview of a community like this.

You updated your question to restrict answers to C++ programmers. For my background / qualifications: I cut my teeth in C, and I can code in C++, C#, and Java. And I like to chase race conditions between threads because I think it's fun. Yes, I "get" bit twiddling.

Your answer and decision wraps around this: Whether or not someone can change depends upon the individual and if they want to change.

But let's start with some questions of you:

  1. Have you asked him about the code and the example you mentioned? What was his impression of the review?
  2. Did you give him specifics during those 6 months about understanding memory manipulation and making sure his code didn't have memory leaks?
  3. Were you providing reasonably frequent feedback during those 6 months to indicate whether he was making progress or not.
  4. Did you explicitly call out that his old way of coding was no longer acceptable in new code?

You need to make sure you can say yes to all of those questions. If not, there's still a burden of proof upon your part for communicating with him.

His response to your recent review is going to be the most telling part.

If he's been trying, and shows some signs of progress then maybe you need to review your mentoring process. If anything, maybe you need to consider pairing him with a more experienced programmer so he can get some immediate feedback while he's making design decisions. I'm not a fan of pair programming, but it can be very useful in a case like this. Continually sending him off to make more and more revisions to old code isn't always a practical route for learning.

If he hasn't been trying, then you need to understand his motivation better. Did he not understand that he needs to try harder? Does he just not care? Are there other areas on the team where his skills would be a better fit and he's more interested in that? If he didn't care to try, then you need to understand why.

From there, you'll know whether he wants to change and whether he can change. No desire to change is equivalent to not being able to change. If there's desire and a degree of progress, then strongly consider changing how you are trying to rehabilitate him.

  • 1
    +1 for "Continually sending him off to make more and more revisions to old code isn't always a practical route for learning" – Bill Jun 26 '13 at 20:44
  • +1 for the last paragraphs. Progress achieved by someone versus effort invested in guiding that someone both need to factor into any judgement of performance. – Marjan Venema Jun 26 '13 at 20:56
11

I'm afraid his bad code is not the only problem in your team.

  1. Who reviews his code? Why did he slip away without a warning for accepting code with memory leak vulnerability?
  2. Why didn't stress tests find this problem? Do you use them? If yes, then why aren't they working?
  3. He was left unattended for a long period of time. Why?
  4. He's not using the tools you gave him. How did you motivate him to start using proper tools?

You say he's been in the company for the extended period of time. Firing such a person is rarely a good idea (unless he's a Wally-type of employee). Their knowledge of client needs, products you own, etc. is often much more valuable than the code they write.

Solutions:

  • move him to QA to let him learn what to avoid
  • pair programming with someone who can point out his errors
  • extended QA effort on his code
  • make him write stress tests, if he sees his dev machine crashed after creating and destroying 10k of objects maybe he'll learn
  • a few/all of them above :)
Andrzej Bobak
  • 1,276
  • 1
  • 13
  • 21
3

Making a decision to fire anyone is a hard decision for anyone to make. Your situation though is compounded by several factors:

  1. It appears that this developer has been in the company for several years
  2. The developer writes all of the companies C++ code
  3. It appears that before you no one ever discussed the level of poor code with the developer
  4. As a new manager you have no idea of who/what the developer knows in/about the company and what the political ramifications of firing the developer are

That said you have spent the last 6 months showing the developer the error of his ways and his new code has not yet improved.

At this stage you really need to start some proactive management so that within 3 months you have

  • A decent C++ programmer who knows what he is doing

or

  • Terminated the developer.

In order to do this though you need to sit down with the developer, explain what is wrong in writing/email, explain how the developer can improve and very very clearly state that if there expected improvement does not materialise then he will be terminated in 3 months.

You also need to be very clear that the improvement is expected from this point on for the rest of his employment with the company and not just for the 3 moth period!

You should also inform your own manager and the HR Department (if any).

During this process you will have to actively manage the developer and review tasks/code every 1-2 days and ensure they are up to scratch, detailing those that are not and explain what can be done to improve them.

armitage
  • 652
  • 4
  • 11
1

Either you haven't been clear about how seriously you take his poor workmanship (i.e. it's possible he sees what time you've spent with him as an option if he wants to improve rather than an absolute necessity), or he has an incredibly bad attitude that's unsustainable. If it's not already clear to this developer that you're considering his position over this issue, then it needs to be spelled out (assuming your leadership are ok with your authority to terminate). The shock will hopefully bring about change.

The employment decision has much wider implications than just this guy though, you need to consider the impact upon the team. If his attitude is allowed to prosper, it can provide either resentment from others or have others feel that this sort of thing is ok too. From the team's angle though, it has to be absolutely clear that if he did go, it was for the right reasons and he had ample opportunity to improve.

One gem I picked up on a course years back is the fact that people with technical knowledge that others don't have can lead management to give them slack. It's bad for the team. You may be fearful of losing the only c++ developer, but they can be replaced. Obviously there are inherent risks if he knows the released products well, but often I've seen people with seemingly irreplaceable product/technical knowledge replaced more easily than anticipated. Teams and organisations can often fill in gaps that initially appear tough to fill. Of course if he doesn't have c++ skills or organisation specific knowledge that you think will be tough to replace, there's much less of a problem!

Wayne M
  • 154
  • 3
  • 1
    I suspect this guy woud be absolutely flabbergasted to find out that his manager is thinking of firing him. Some people you just have to hit over the head with a plank and flat out tell them that they have to improve or they will be fired. – HLGEM Jun 26 '13 at 17:06
0

Of course you should not. Remember, this is not a charity, you are exchanging money for work. If he isn't holding up his side of the deal then like any transaction I'd stop paying.

MetaGuru
  • 2,663
  • 3
  • 22
  • 31
0

If you want to give him a chance, develop a standardised test that gathers metrics on memory leaking. Monitor his progress on a weekly basis, insisting on seeing the code that he changed, and look for improvement. If he can't manage at that point, sack the useless invective.

Jack Aidley
  • 2,954
  • 1
  • 15
  • 18