62

I'm technical lead and we have a recent hire that's very inexperienced. He's also very opinionated and proud for a newbie and his code style diverges too much from the team. But he still produces low-quality code compared to the other employees.

This is not a problem, though: I'm supposed to catch those issues and teach him to improve in code reviews, feedback sessions, etc. Problem is: when I review his code, I have to leave too many comments to the point feel like I'm overdoing it. A few times I did let some issues slide, but this always ends up costing another developer's time (or mine).

I also tried one-on-one feedback sessions to avoid public reviews, but it was fruitless, as the developer was trying to justify every piece of feedback to the point of derailing the session.

What's the best way to deal with this? I'm getting good feedback from the team regarding the reviews, and I am preventing some production issues, but I feel like the "bad cop" every time I walk into his pull requests.

Bernhard Barker
  • 13,022
  • 4
  • 39
  • 62
  • 7
    How many devs are in the code reviews? I always start a code review by reciting the ground rules, e.g. to treat the critique in an abstract manner; make it impersonal. When other devs undergo the code evaluation, make sure that the new dev critiques the less experienced people too. This will help the new dev converge into the expectations a bit easier than endless 1-on-1s. – jdb1a1 Jul 14 '20 at 19:11
  • 32
    Have you considered automated tools to help? If issues are well-defined, there are lots of tools out there that can automatically point out the problems. The developer might get conflicting views about ones you let slide or miss, "but it wasn't a problem last time - why are you saying it is now". It's hard to know the exact issues but at least this way they can get instant feedback and potentially fix a lot of problems before you see it. – Eliott Robson Jul 14 '20 at 20:31
  • 25
    Especially regarding "code style", having automated checks such as Checkstyle is a good idea even with experienced developers. – chrylis -cautiouslyoptimistic- Jul 15 '20 at 01:44
  • 3
    For the issues raised in the code review, are they objective corrections that are clearly outlined or something subjective that is a personal style? If it is objective, does this developer have access to proper documentation of what is expected of him? A couple sample, some less severe, some of the most severe, and we can better gauge what is being reviewed. – Nelson Jul 15 '20 at 02:13
  • 4
    +1 for automated code analysis. We took a lot of heat out of the code review process by delegating the first run to Sonar. Fix the auto-generated flags then we'll look at it. – Trent Bartlem Jul 15 '20 at 06:30
  • Did you involve management? What are expectations that were set by his superior regarding adherence to common standard? What are expectations from adherence to code reviews and job seniority? Those things should be explicitly agreed on before the new developer starts coding. – Euphoric Jul 15 '20 at 08:28
  • 2
    Have you tried asking him what you are going to point out in his code? – Andrew Morton Jul 15 '20 at 08:35
  • 2
    "Are you willing to write code that is acceptable to your employer, regardless of whether you like it?" If yes then "Good, then please act upon the feedback you receive." If no then suggest self-employment as a more suitable career path and report to HR/your boss. – cja Jul 15 '20 at 08:45
  • @EliottRobson we have plenty of automated tools, including custom linter rules, third-party tools. The main issues are introduction of bugs, security issues, weird variable naming practices, badly written tests and overengineering. –  Jul 15 '20 at 09:07
  • 1
    @mtw "weird variable naming practices, badly written tests and overengineering" I've got exactly the same problem. But slightly worse because I'm just a senior dev. – dan-klasson Jul 15 '20 at 10:17
  • 3
    As a developer who’s been in a senior/lead role for 10+ years, to me the most concerning thing you mentioned is that your efforts to give feedback were fruitless. It sounds like the problem isn’t lack of aptitude, but lack of humility. No amount of automated or documented processes can fix that. I prefer a developer with average aptitude and a willingness to accept suggestions over one with above-average aptitude who's unwilling to admit they’ve made a mistake. The latter has caused me more issues in our production environment than the former. – Ricardo van den Broek Jul 15 '20 at 14:04
  • 2
    One thing about learning professionalism in any job is that it's not about you, and sometimes decisions that are sub-optimal for you are right for the org. You are doing this person no favors by ignoring the meta-problem here: let's say that you convince him/her that your style is "correct". He/she is just going to get into another fight with the next reviewer at the next job. Focus on the professionalism angle, i.e. "you will be in a number of jobs over the course of your career most of which will if you're lucky have an in-house style guide and you will have to adapt to this, repeatedly". – Jared Smith Jul 15 '20 at 16:28
  • 1
    @RicardovandenBroek that's the thing that has been worrying me the most as well. If it were a very experienced developer with the same attitude I would probably have the same problems. –  Jul 16 '20 at 09:01
  • 1
    There's an easy solution: don't hire that kind of worker! – David Jul 22 '20 at 14:11
  • @David I agree with your point. Unfortunately he was hired by my superior, but if he had behaved in the interview the way he behaves at work, then I would definitely have flagged his application. I'm all for having Juniors in the team, but if they're unenthusiastic about learning more or are not accepting feedback, then they're not worth having in the team. –  Jul 24 '20 at 10:12

12 Answers12

62

On being a "bad cop"

As was mentioned before, the way to go is detaching yourself or any person for that matter from the issues to be raised. This means:

  • Your rules need to be clear and written down, be it in a wiki, a styleguide, company documents, whatever you are using. This material must be accessible to the dev in question.
  • When pointing out mistakes in a review, do not use phrases that involve you in any way. Instead shift blame to your documents, such as the styleguide and to your processes in general. An example of this can be, "Line X: According to the styleguide [link] static member variables have to follow the Y pattern."

You will not be able to avoid the bad cop feeling entirely, this is part of reviews. However with careful tone you can establish a review culture, where it is clear that not a developer is questioned, but only the code itself. It needs to be understood by all parties, that a review is not about criticizing a person or their work, but merely about impoving code and therefore your product.

Assigning proper tasks

This is probably my most important point and the one I think justifies my answer in the first place, as there are redundancies accross all answers posted:

Another answer by @Ertai87 mentions that correcting all minor mistakes is exhausting, I assume both for the reviewer as well as the reviewee. You also mention there is so much to correct, that the whole exercise somewhat derails. The answer I am referring to then states to focus on the major issues and ignore minor problems.

In my view this is not the correct approach.

When the tasks solved by the developer in question are so laiden with issues that reviewing them turns into an enormous undertaking, then I want to argue these tasks are too large for the developer in question. They are not ready and need to be assigned smaller tasks and get down the minor stuff first. That means, assigning e.g. bugfixes that only come with presumably only a few lines of code, only very minor features and other issues of the sort. Otherwise you will pass a ton of nonsense into your codebase because you are so busy with fixing their major mistakes, that you cannot afford to fix all the minor nonsense. Ultimately this will likely be time spent by other employees, who end up fixing all these things when they in turn work on the same code passages.

You should not expect your junior to be at the same level as everyone else, as the process of improving must be incremental. Still they are an employee, so you can expect that they bring value to the company, even if that value is relatively minor and only comes with and increases over time. So assign them smaller tasks and let them get the basics down first. The better they get, the larger their area of responsibility may become and so their tasks can increase in significance too.

Ask yourself this. With the time spent fixing that developer's code, how much time in comparison would you have spent doing it yourself?

Distributing reviews

As a team lead it is not written in stone that you have to review all code. Reviews can be done by all experienced employees, you have the option to use this tactic. A common way of doing this is to have a set of reviewers and a designated timeslot, e.g. once a week, when reviews are being processed. During that time all members of the set are required to review issues that are awaiting acceptance/rejection.

There are three main advantages to this:

  • Code reviewing is a task that requires a lot of concentration. You can do only so much of it on your own during a day before you start passing mistakes into production. More people on this task means more concentration as a resource.
  • No matter how experienced you are, there are likely some patterns in your code and some mistakes you repeat and are unaware of. This is true for your peers as well. When multiple people review members of your team and each other, at the very least the reviewee gets to see other patterns and other ways of solving problem X. This way knowledge is distributed in your team.
  • The more people do reviews, the less a single person is running the risk of becoming the bad cop.

I will say though, this may depend on the company and the processes in place. Some workplaces may require a team lead to sign off on each and any piece of code and some workplaces may even do so due to a specific qualification that only an expert brings to the table. An example of this could be safety in a medical setting. If there are no such special requirements, but the processes currently require you to personally review all code that goes to production, then this can be raised with management arguing for increased efficiency of the team. Only you will know how things work at your company, use your best judgement whether distributing reviews can be achieved at your workplace.


A personal note: When we started code reviews at our company it was bumpy at first too, because it is hard not to feel criticized when your merge request is rejected with a bunch of stuff to fix. By now the team cherishes code reviews. Personally I have learned a lot from getting my code reviewed and so did my peers.

On defensive behavior

There are some things that can be discussed and some things that do not require a debate. Discussing this or that architecture is not uncommon. When doing so it is important to have a good reason for you want to change implementation X to implementation Y. Just saying "this is better" is insufficient. Of course you can go the authoritative way, but this is likely to demoralize and can show a lack of insight. On the other hand, when your team developed your styleguide I would expect you to have put some thought into why you decided you wanted to do thing X in way Y. These things should not end up in endless debates every single time, at least if the team's concensus on the matter has not changed.

All in all defensive behavior is not that quick or simple a problem to solve in my experience. I suggest doing one-on-one talks from time to time. Akin to performance reviews, but intended to be a non-interrogative talk between two team members, rather than a boss giving their subordinate the business. This is a time where you can share your gripes with how the employee performs by suggesting improvements. It is important to listen to their side as well. Are they content in what they are doing? If not, what are the issues on their mind? How can these be resovled?

That being said - if all such attempts do not bear fruit, then the authoritative way may be all that remains. In this case, explain to the developer that their performance is not satisfactory, as hard as it seems. This is basically a warning shot and at this point I would consider letting that person go.

I understand this may sound harsh, but ultimately every employee needs to bring value to the table eventually. The value of a junior in the beginning may be barely above zero, it may even be an investment into future productivity, without any immediate gain. However if time passes and no improvement is seen, then the company is wasting money and the employee is not the right fit for you.

There are a lot of things to try before this happens though, some mentioned above. You should ask yourself, if you can improve your communication with that employee and go from there. Are you phrasing things that force them into a defensive stance? If the developer turns out to be an asset to the company that was only hindered by poor communication between them and you, then everyone wins once this is recognized and resolved.


Another personal note: I have been working with and teaching quite a view juniors by now in my last couple of companies - mostly students in their bachelor's and master's, doing the first steps coding for real world applications, but also self-taught coders as well as juniors with a different educational background. One thing many students learn after taking this step, is that technical skills, no matter how good you are, are one part of a larger equation. Soft skills are largerly important and need to be caught up on if necessary.

Nowadays we filter candidates by assessing their character rather than their technical skill. They have similar education and we rely on this fact. Personality compatibility however is highly important, because one bad apple can poison the whole basket. So far, primarily by promoting a very welcoming company culture, we have been able to integrate all of our students and every single one of the became an asset eventually, but we take our time with them and don't assign someone who is learning the ropes giant tasks. As said - progress is incremental.

I hope this wall of text helps you in one way or the other. Good luck!

Koenigsberg
  • 1,534
  • 11
  • 15
  • 2
    Excellent answer! I would also recommend this book, Code Complete 2, to help with making checklists and style guides. https://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ – Stephan Branczyk Jul 15 '20 at 00:25
  • 1
    +1 well thought out and points out how the team as whole is important, skill can be improved easily, personality is much harder. – DrMrstheMonarch Jul 15 '20 at 11:15
  • 3
    On the subject of workplaces where a lead is required to review: It's usually still feasible to have someone else on the team review it first, for general compliance and quality, and then once it's up to an acceptable standard have the lead review for whatever their specific expertise is. In some cases, that might still involve reviewing everything in detail, but it would at least reduce the workload on the lead. – Bobson Jul 15 '20 at 13:21
  • 4
    Having dealt with this issue myself on multiple occasions, I especially support the idea of properly assigning tasks. Someone who doesn't yet understand how the team organizes code, local standards, formatting conventions, etc... really shouldn't be writing (for instances) entire models and classes. Or they should be doing so with the understanding that they need to be mimicking the patterns and habits shown elsewhere, because when it comes to code, the most important thing is consistency. – Conor Mancone Jul 15 '20 at 13:37
  • 2
    A style guide need no justification beyond, "We made an arbitrary choice and are sticking with it to maintain a consistent code base." Of course, having a proper justification is preferable, but a substantial part of the motivation for having a style guide is to make the code consistent. – Brian Jul 15 '20 at 14:18
  • @ConorMancone yeah, egalitarian work places are cool when everyone is at the same level or at least there is a general base level that allows them to pick tasks responsibly. It can get pretty terrible when the experience varies too much but everyone gets to do all the available tasks - even with everyone following the rules and from their perspective doing their best for the team. – Frank Hopkins Oct 04 '20 at 16:53
48

If there are that many mistakes in the code, maybe a code review is too late to catch them. Maybe you need to take a step back. There are some alternative approaches you could take:

  1. Training. Doesn't have to be a course. Could be a book, a video series, an exercise site.

  2. Personalized guidance. Instead of repeatedly pointing out the same mistakes in code reviews, maybe take him aside and explain the most common ones in more detail.

  3. Pair programming. Let him shadow a few of the other devs. It's the quickest way to pick up the in-house code style.

  4. Mentoring. Officially assign another dev as a mentor to help out with code reviews. Ideally, this should be something both parties agree to.

Llewellyn
  • 2,157
  • 2
  • 13
  • 16
  • 6
  • requires the individual to want to improve, which doesn't seem to be the case here. 2. seems to have been done excessively. 3. May be an option but expensive. 4. again - needs cooperation. And you forgot 5. : Let him go.
  • – Fildor Jul 15 '20 at 07:47
  • 25
    @Fildor The idea that pair programming is somehow expensive is a huge misconception. Making software is not a production line where everyone needs to be busy and maximally utilized. It is a creative design work. And best designs come from collaboration and communication. – Euphoric Jul 15 '20 at 08:22
  • 2
    @Euphoric I know what you mean. I've done pp before. I sometimes do it occasionally. It is expensive. That has nothing to do with if those expenses are justified or create a ROI later on. Also, in this instance, pp wouldn't have the benefits nor even the intent you describe. It would be merely babysitting. Expensive babysitting. – Fildor Jul 15 '20 at 08:26
  • 11
    @Fildor, There's already expensive babysitting happening: it's just happening during code review when the dev thinks they are "done" and are defensive of their decisions. In my experience, the earlier in the development process feedback is given, the more likely it is to be taken well, so switching to pair programming for a while could potentially yield improved outcomes without using up much more time. – Parker Coates Jul 15 '20 at 12:40
  • 1
    @ParkerCoates Didn't argue against that. May be worth trying. – Fildor Jul 15 '20 at 15:14
  • @ParkerCoates I agree that pair programming is a valid option, but also very character depending. I know people that mentally shut down when they need to pair program, the presence of another one disturbs them in their thoughts or gets them to switch into executor mode ("alright, tell me what to type"), the latter often happening especially with juniors or people that feel inferior to the other or that are very defensive and avoid direct confrontation. Again, by all means, consider it or try it out, but like many tools their usefulness is context dependent. – Frank Hopkins Oct 04 '20 at 16:58