views:

327

answers:

9

Recently, we've come across an issue at work where if one person is working on some code by themselves, it seems to come out with the other team members looking at it and going "Huh? That's ugly, unmanageable, I need to rewrite that"

In fact, recently, I myself have had to re-factor something that was written the week before so that I'd be able to add in my (related) feature.

I know that Pair programming is the way to go for this, but we have an uneven team (3 members). As our team is being pushed pretty hard at the moment, we really don't have time for Peer Reviews (though we can do Pair Programming, as we're allowed to estimate that into our task estimates)

I'm just curious as to how people would suggest we overcome these issues with poor code being generated.

+2  A: 

So:

  • you are being pushed pretty hard
  • your code is of poor quality

Do you think the two could possibly be related? The answer is to fix the schedule.

anon
Our code seems to only turn out poor on odd occasions, and only when we have a single dev working on it.
Mez
Assuming pair programming is more efficient, then someone programming alone is likely to feel under more pressure if a schedule is unreasonable, and thus make even more mistakes than they would in a non-pair environment.
anon
+6  A: 

I'm surprised that you don't have time to do peer reviews but you have time to do paired programming. Is the latter not a much bigger sink of time?

We also have three developers only at our company and, surprise, surprise, we're being pushed hard at the moment. I'm pretty sure my boss would laugh at me if I suggested paired programming because that would be viewed as doubling the number of man hours for a task even though in practice that's not the result it should produce. Our peer reviews are never more than an hour and that is an extreme case. On average I would say they are probably about 10 minutes and, per developer, only happen once or twice in a day.

IMO you should give peer reviews a try. You often find that the offending people (i.e. the people writing the lower quality code) eventually realise that they need to make more of an effort and the quality improves over time.

Troubadour
You don't need to offend people in peer reviews.
RichardOD
When he said "the offending people " he meant the people making the mistakes not that someone was being offended.
Unkwntech
Thanks, Unkwntech.
Troubadour
Some argue pair programming is not a time sink. It is a real time peer review and prevent silly design decisions.
John Nolan
10 mins for a peer review in my opinion sounds very short.
John Nolan
Thanks for the replies John.I should point out I've never tried pair programming so when I asked if it was a bigger sink of time over code reviews it wasn't a rhetorical question. I really don't know. :)The ten minute quote for peer reviews was an average based on the fact that we like to get everything reviewed, even one-line changes which can be as short as ten seconds. It's amazing how many one line changes cause the biggest problems :).
Troubadour
@troubadour: pair programming is anything but a waste of time. While one types the code away the other is already doing the thinking of the process to do next and the one being programmed if it fits the rest of the solution. Pair programming may look like a waste of time but in fact it turns out that code that's written by a pair is much more stable and better suits the whole app.
Robert Koritnik
@Robert. Thanks, that makes a lot of sense and I certainly do believe you that the code would more stable thereby saving on time fixing defects - time which is always underestimated. It *is* something I'd like to try at some point but, as I say, I don't know whether my company would go for it at the moment.
Troubadour
Pair programming for us a lot of the time will speed things up, because of the shared knowledge ("oh you do that here" rather than *hunt through code looking for some random bit you need to change*)
Mez
@Troubadour: I would think that getting everything reviewed, especially all of those one-line changes would be a bit over the top. I agree that some one-line changes could cause significant issues, there is a time and a place for these sorts of reviews. Sometimes you have to trust each other.
akf
+3  A: 

If you have three developers and each of you think the others code is not good, you urgently need peer reviews.

akf
And maybe to be locked in a room until you can all agree that your own code is unintelligible...
Steve Jessop
+14  A: 

When you work alone, and produce code which your colleagues find ugly and unmanageable and needs to be rewritten, then do you:

(a) agree with them when you look at it a second time,

(b) disagree?

If (a), then the problem is that on your own, you aren't fully clarifying your code when you write it. Since pair programming is the only thing making you write decent code, I suppose I'd recommend that the "odd one out" should work on tasks which do not involve writing long tracts of bad code: bug-hunting; maybe writing test code, since that tends to be a bit less fiendish. Meanwhile, work on improving your skills at writing better code - perhaps do reviews of your own code from a few months ago, and make notes as to what was wrong with it.

If (b), then the problem you have is incompatible ways of expressing your ideas. The code may not be bad by your standards, but it's mutually incomprehensible, which in a corporate setting means it's bad code. Pair programming means what you write is a compromise that 2 out of 3 of you understand, but that's not really a solution. You need to come to some mutual agreements about what you find most difficult about each other's code, and stop doing that. And you all urgently need to start thinking of "code quality" in terms of "my 2 colleagues will like this code", not "I like this code".

Either way, you all need to work on writing code for the purpose of being read, rather than for the purpose of getting the immediate job done as quickly as you possibly can. Personally I have done this by trying to express things in the way that I think other people might express and understand them, rather than just what makes sense to me at the time. Eventually it becomes habitual. When I write code, I write it for a public audience just like I'm writing this post for a public audience. OK, so on my personal projects it's an audience of people who think just like me, whereas at work it's an audience that thinks like my colleagues. But the principle is to write code as if someone's reading it. You're explaining yourself to them, not the compiler.

Not that my code is the best in the world, but I do think I benefited in that my first job was in a company with 30-odd programmers, so I got to see a wide range of ways of thinking about things. Also a few examples of "what not to do", where one programmer had done something that nobody else could easily understand, and therefore could definitively be said to be bad. With only 3 people, it's not clear whether a 2 v. 1 difference of opinion means that the 1 is a freak or a reasonable minority. When I did something and 4 or 5 people could glance at it and immediately say "eeew, don't do that", then I started to really believe it was just a dumb idea in the first place.

I'd also recommend that if you aren't allowed to budget for code review, lie and cheat. If you're heavily re-writing someone else's code, you're effectively taking the time to review it anyway, you just aren't providing the feedback which is the worthwhile part of code review. So sneak the review in under the radar - write a function or three, then ask a colleague to look at it and give you instant feedback on whether it makes sense to them. It helps to have a conversation as soon as you've done it, with the code on the monitor, but do try not to interrupt people when they have "flow", or to get into lengthy arguments. It's not pair programming, and it's not formal code review, but it might help you figure out what it is you're doing on your own that's so bad.

Steve Jessop
A: 

You should still pair. Set up sessions say 1 day per week and rotate the pairs. This should keep your manager happy and increase the quality of the code, improve communication. If you keep metrics on how many faults happen in paired vs solitary coding you should start to see the benfit and display this to your manager,

eg This took x man hours but saved on average y in defect fixing. Additionally the clode is cleaner and will take less time to alter then next time we touch it.

From there you will have hard statistics and you can start to code more.

Basically your story seems to be the same as mine.

  1. No time to do things.
  2. Mistakes happen.
  3. Rush to fix it (taking more time)
  4. Go to 1

You need to stop the rot.

John Nolan
+1  A: 

Pair up all three at once.

Set up some coding standards.

Use a dunce cap for build breaking developers.

Perform daily stand up meetings to communicate progress.

Also try peer reviews twice a week, like Tuesday and Friday.

Devtron
+1  A: 

Pair Programming doesn't have to be all day every day to be effective. I have seen good results from even an hour or two working together each week. One way to go would be to pair A & B for a while, then A & C, then A & B... with a lot of individual time in between.

It also depends a lot on the personalities and chemistry of the team members. Two of the three might work exceptionally well together and you'd want to benefit from that.

catfood
^ I completely agree, especially with the first part of this answer!
Devtron
A: 
  1. Code reviews
  2. Enable Stylecop that will force you to write readable, standardised and manageable code
Robert Koritnik
1 > 2. I've seen a lot of unreadable code that passed the style guide, but not much unreadable code that passed code review (except in those situations where the writer and the reviewer had been living in the same bunker and developed their own private set of assumptions).
Steve Jessop
A: 

We use code reviews. Additionally there are some single task: changing a diagram, installing some stuff...

crauscher