views:

305

answers:

11

I currently support an application at work that was originally written by a team of four but has now reduced to just me. We recently got a contractor in to look at some performance issues while I'm occupied with other things.

While the contractor has appeared to do a good job with the performance, they have also gone through large amounts of the code replacing the pre-existing style with their personal preference.

Unfortunately we don't have a coding standards doc, just a general rule to adhere to c# general rules.

As an example of what they've done, it includes:

  • removing nearly all the uses of the 'var' keyword
  • Anywhere with an if statement and a single line, they've added curly braces
  • Removing most of the lambdas and replacing it with more verbose code
  • Changing method signatures so every parameter is on a separate line rather than one line

We also operate a TDD policy but the test coverage, especially on the performance specific parts, is very low leaving very little documentation on what they've changed and making it even harder as their checkin comments aren't particularly helpful and the actual functional changes are lost amongst the swathe of 'tweaks'.

How do I talk to the contractor about this? Obviously there's not much impetus on them to change it given they have no responsibility to support the project and they don't seem particularly receptive to change.

Or should I just put up with it for the short duration of the contract then change everything back to the code formatting we used before?

Made community-wiki 'cos there's probably not one right answer here.

+8  A: 

Anywhere with an if statement and a single line, they've added curly braces

This one and the only one may be beneficial.

  • removing nearly all the uses of the 'var' keyword
  • Removing most of the lambdas and replacing it with more verbose code
  • Changing method signatures so every parameter is on a separate line rather than one line

These ones make little sense to change.

Tell him he's not authorized to restyle code. You won't be paying for the time wasted for these activities and they'll have to use their own time to put things back. That should provide a refreshment.

These things should be discussed in advance. You should state clearly what activities are allowed and what not. Not a long ago there was another similar question here about a contractor who would put his initials all over the code including database entities. It was some perverse kind of self-promotion for which there is no place in someone else's code.

P.S. There may also be a possibility that by doing all these things your contractor is artificially creating extra workload to bill you more hours.

Developer Art
I will certainly establish in advance in future. I just somewhat naively hadn't realised it would be an issue when we got the contractor in.I will take Derek Clarkson's advice and talk to my boss about it and then see where it goes.
Wysawyg
I find the argument of "time" wasted on restyled code to be laughable it's very easy to have resharper configured to do all of those except replacing the lambdas. Which since he was hired to address performance is minorly acceptable since there is a slight cost of using lambdas albeit that would be a very unlikely source of performance problems.
Chris Marisic
What is beneficial about wrapping shortcode if statements in curly brackets? If anything I'd say that was one of the biggest wastes of time in the list.
WDuffy
@WDuffy: In nested if/else statements it's easy to assign a code line to a wrong statement, a popular source of problems. Plus when adding a second line it's easy to forget that without brackets it's on its own, not belongs to the if/else statement. Just a precautionary measure.
Developer Art
@Developer Art - Pecautionary measures would be justifiable if he was debugging an error prone codebase. However, in this case the code is running fine and has a solid test base, the contractor is only involved for optimisation purposes. If developers have nested if/else statements odds are there are more serious problems in the code than missing curly brackets.
WDuffy
@WDuffy The Code is very low in nested if/else, in part because in my naive youth I took a job doing COBOL and seeing as you have a 78 character line limit, it gives you a deep hatred of any form of nesting (It also gives you a deep hatred of COBOL).
Wysawyg
+2  A: 

How do I talk to the contractor about this?

Politely: explain why you want to minimize changes to the source code.

ALternatively, have a code inspection of the changes before check-in: and don't allow check-in of changes that you don't understand/don't want/haven't been tested.

ChrisW
+1  A: 

The problem has happened now, and as the other said it's an unjustifiable waste of your money and it's outright impolite (as correct as the curly braces thing may be).

Certainly to help prevent future problems, and maybe helpful to resolve this, I'd advise you set up a stylecop implementation - at the very least they can't fail to be unaware of when they are breaking your rules.

annakata
+1  A: 

I think we all know the temptation of seeing coded we think is "not the way I'd do it". But we resist it.

I would have a chat about it with your boss first to get their take on it. But the first thing that springs to mind is that unless you specifically asked the contractor to do the work, he was not doing what he was hired to do, regardless of any benefit he thinks he may have been adding. So there needs to be a discussion about that.

The next thing that sprung to mind is that regardless of how good they may be or well intentioned, people who make bulk changes without discussing it with the owners of the code are bad news. They will piss people off, or worse introduce bugs and unforeseen behavior that you will have to clean up. He needs to be set straight that doing this sort of thing without permission on other peoples code is not acceptable.

When I see things I don't like in others code which are serious enough to warrant attention, I check with the owners of the code first. Even if there are obvious bugs, it s their code and their decision about cleaning it up, not mine.

Derek Clarkson
It certainly sounds like the contractor was hired to address performance issues that the OP said they were addressing well.
Chris Marisic
It's not that they've actually refactored bad code to good or hard-to-read code to more readable. I wouldn't mind that 'cos I agree with the Boy Scout principle and leaving the code base cleaner than when you entered it and I'm sure there are WTFs in the code base. The problem is that he's just tweaked it.
Wysawyg
+5  A: 

I'm a contractor (sometimes) and if I did this I would expect to be shown the door with great speed and no payment. Seriously, this person is hired by you and should be doing exactly what he is told to do, no more and no less. And don't worry about being "nice" - contractors don't expect that from permies.

anon
A: 

Well, smells like a solution wide code reformatting to me, that could be automated/enforced by settings in a tool like Resharper. I would think it very impolite and would ask him to refrain from pressing the "Reformat all code according to my personal taste" button.

bottlenecked
We have ReSharper in house and I offered him use of that (because we have spare licenses) but he refused, saying he preferred not to use it. I thought that was fair enough at the time until I saw all his changes. So yeah, he is changing it all manually which is even worse!
Wysawyg
+2  A: 

Implement FxCop - this should be your first line of defense. Also if you use source control (if you don't then implement one ASAP), make sure to use dev labelling (only build on file that have been labelled for the build), and don't give him rights to move labels on the files. This way you can scrutinize his changes, and refuse to dev label his code until it meets your standards. Whatever he codes won't make it into QA until you move the dev label to the revision in question, so he's pretty much at your mercy there. Note that some shops don't use a single label for their sandbox builds, they like to apply new labels even to the sandbox, so you may be inclined to do that as well.

code4life
+1  A: 

As others have said, these changes are simply for coding style. If he is there to improve performance, he is wasting time with these changes. If he can't cite how these changes will improve performance, then his OCD is just running up the bill.

I would say, "I appreciate your changes to the coding style, but lets focus on non-style changes to areas of the code that are causing the slowdown."

Software.Developer
+2  A: 

If a contractor did wholesale reformatting of code without authorization, I'd give him one and only one change to put things back the way they were -- and on his own time.

In addition to the valid points others make, consider the version-control nightmare this causes. Instead of the clean progression of a few lines added here, a few lines changed here, you now have this "rift" in your source control database, so that any comparisons between versions before and after this contractor's "improvements" will be meaningless.

Have the contractor back out all of his changes. Today. And on his own time.

Bob Kaufman
That's part of the problem. I'm trying to code review his changes (I know, little late) and he's made infrequent checkins, unhelpful comments and hence made it very difficult to see what changes because it needed to and what changed because they wanted it.
Wysawyg
Agreed @Wysawyg that reviewing changes are almost impossible when style changes along with a few lines of functional change. Unhelpful comments make the situtation a lot more difficult too. A good contractor will try and adapt to the local methodologies and styles, a bad contractor will ignore this. Raise it with your manager as it is clearly unprofessional. (I am a contractor and try to abide by local coding conventions even when these are different to my own preferences).
PP
+1 for the version control issue
JonoW
+1  A: 

This is quite common my experience, that people can't resist making 'improvements' and suddenly you find you're billed for stuff you didn't want. Sometimes I'm sure it's done deliberately to get more paying work, but mostly I think it's a developer getting side-tracked and unable to deal with leaving 'wrong' code. It might require a bit of a battle, but you basically have to keep reiterating "don't change anything you're not asked to work on". Depending on his personality, you might just have to ask once nicely, or get someone higher to force him.

John
A: 

First, as others have said. You are paying the bill. He is not an employee. His job is to do what you ask him to do, and only what you ask him to do, otherwise you can show him the door. Always remember this. You are driving the boat, not him. You can try to not pay him, but that will be hard to do if you have a legal contract and there is nothing in it about leaving code as-is. But, you can simply let him go at any time.

Second, if you can't get him to stop and revert, and you can't get rid of him, you can tell him that if he plans to do style changes, then he should do all style changes in one check-in with absolutely NO code changes. This allows you to move forward from a base set of code that can be diffed to see code changes.

Third, make him explain the justification for the changes he's made. Removing var has no performance benefit.

Fourth, and this may suck a great deal, but youc an always use ReSharper to put the code back to your accepted style after the fact. It's more work, and you still have borked diffs, but oh well. The lambdas are harder, and that's the one you should really get on his case about.

Fifth, to drive home your point, force him to back out every change he's made and re-implement only the code changes, and not the style changes. That should open his eyes as to the mess he's created when he can't figure it out himself.

Finally, you may just have the bite the bullet and PAY him to revet back. Yes, it sucks, but since you made the mistake of not policing him, not specifying up front what you wanted, and what he's not allowed to do... You will pay the ultimate price. You can either pay him to do it, pay someone else to do it, pay you to do it, or live with it (and pay the price of the borked diffs). Any way you cut it, it will cost you money.

Mystere Man