Wednesday, November 11, 2009

Clean code = clean hands

Here's a situation you surely have seen in the past:

You're building a new app, and your code starts out pretty uniform.  You follow some basic coding conventions.  You need to bring in another pair of hands, so you hire someone.  He does good work -- but all his code completely ignores the existing coding conventions. You've prodded him about coding conventions, but to no avail.  Now you've got database columns of TradeId in 5 tables, but trade_id in his new table.

What do you do with this guy?  Like I said, his work is otherwise good.  There's a good chance that a replacement would not be as good as him.  In baseball statistics, you'd say he has a solid VORP.

Do you micro-manage him?  Make his life hell?  Or, on the other hand, should you just accept this flaw as part of the package?  Perhaps his brain does not accommodate thoughts of coding conventions, and to impose it would greatly affect his productivity.  Some people could be like that.

Code reviews might catch these kinds of problems.  But, every place I've ever worked had such extreme deadline pressure that code reviews always got chopped.  I don't think they're a long term solution.

Perhaps a code czar can be appointed to to make sure all code fits in with the master plan, like George Lucas does to ensure consistency in the Star Wars canon?  Almost always, such a czar is disdained by the other coders, or gets carried away and becomes a bottleneck.  People you'd want to have in that role smell the no-win nature of it and avoid it.

My usual solution has been to prod as much as possible, using all the motivational tools in my belt, but ultimately letting it go if that all proves useless.

But, today I witnessed something that totally changed my mind.  This event had nothing to do with code.

In the bathroom, someone was in the stall doing their thing, using the toilet paper.  As I was washing my hands, this person came out of their stall and then proceeded to walk straight out to the work area. 

Yes, I was disgusted.  I was also shocked, because this person was a fairly high member of the department, and known to be a good guy, excellent worker, etc.  I don't know if I can look at this guy the same way now.

Strange mind that I have, I immediately related this to coding conventions. 

Would I eventually get rid of someone who consistently refused to wash their hands after, you know, using the toilet paper?  Absolutely.  Social pressure should work (and probably would in this case).  But if he didn't, he's gone.

You might argue that clean code is not as big a deal as clean hands.  But, as far as your code is concerned, it is.  If one person's code sticks out so clearly, then he's creating a bigger problem.  Like a virus, it will indeed degenerate your code into unmaintainable, unreadable goop.

Clean code = clean hands.  This basic level of social behavior and decency should be expected.  There's no excuse for doing otherwise.

No comments:

Post a Comment